MATLAB Answers


L-BFGS-B with function calculated by commercial software

Asked by Nike Dattani on 11 Sep 2017
Latest activity Commented on by Nike Dattani on 31 Oct 2017
When I search "L-BFGS-B matlab", I find way too many options to choose from. I run a commercial FORTRAN binary twice, and the difference between the two output numbers is what I want to optimize. Therefore I need MATLAB to call the commercial FORTRAN binary twice (via two separate input files), parse the output files for the relevant numbers, and feed the difference between these two numbers into an L-BFGS-B routine.
How would I go about solving this problem?


Show 1 older comment
I wish I got an email notification saying that you wrote this comment. I clicked the first link and it gives examples of how to use the program with an objective function which is specified completely in MATLAB. What if evaluating the objective function requires running a commercial FORTRAN program twice, and taking the difference between an output value from each of those runs?
The second link also seems to calculate the objective functions completely in MATLAB (though it took me much longer to find the examples).
tfile = tempname();
fid = fopen(tfile, 'wt')
fprintf(fid, 'commands for\n')
fprintf(fid, 'program input go here\n');
cmd = sprintf('"%s" -i "%s"', 'C:\Some\Directory\NameOfCommercialProgram.exe', tfile );
[status, result] = system(cmd);
result_numeric = sscanf(result);
repeat for the second call but with different output variables, then call L-BFGS-B with the difference between the numeric results.
Walter, I appreciate your answer VERY much. Unfortunately I did not get an email notification saying that you replied, but was expecting one, so I thought no one replied to this. I ended up convincing the developers of the commercial program to work on a BFGS routine intrinsic to their program, but if it takes to long or doesn't work out, I will come back to this.

Sign in to comment.

0 Answers