Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Minimization/optimization with external function?' topicStudent Support Forum > General > "Minimization/optimization with external function?"

Help | Reply To Topic
Author Comment/Response
Dave
10/29/08 1:52pm

Hello,

I've created the following auxiliary function which outputs some data to a file, calls an external FORTRAN program which reads the data. Mathematica then reads the output from the FORTRAN code, and then performs a calculation, a least squares sum.

Lse[x_,y_]:=(
PSiH[[2,1]]=x;
PSiSi[[1,2]]=y;
Export["PSiH.dat",PSiH];
Export["PSiSi.dat",PSiSi];
in=ReadList["!sirebo_cygwin.exe<mat.in",Number, RecordLists->True];
ESiH=Extract[in[[2]],3];
ESiSi=Extract[in[[3]],3];
((ESiH-(-3.124))^2+(ESiSi-(-1.731))^2)^(1/2)
)

By itself the function works fine, if I give it a value of say Lse[1,1], I get a reasonable output. So far so good. However, I would like to use a standard Mathematica routine like "Minimize" to find optimal values for the input parameters x and y to minimize the least squares sum in the last line.

I tried:

Minimize[Lse[x,y],{x,y}]
that gives an error. It actually writes "x" and "y" to the data files which crashes the FORTRAN code.

Any suggestions how to get around this?

Thanks!



URL: ,
Help | Reply To Topic