Hi,
I want to use the optimisation toolbox, in particular the lsqcurvefit function, to fit the response of an external C programme to experimental data. For testing purposes I have written a C programme which computes f(x) = p*sqr(x), where p is my parameter to be optimised. However, the optimsation alogorithm does not perform any optimsation of my parameter p. It stops after two function evaluation:
Initial point is a local minimum.
Optimization completed because the size of the gradient at the initial point
is less than the default value of the function tolerance.
I checked the first-order optimality and it is zero:
This is my function to the external programme:
function y = myexternal(p,xdata)
writeToFile(p)
system('myprog');
data = textscan(resultsfile,'%f');
y=data{1};
end
I run my optimisation (assuming xdata and ydata is definied) via:
p0 = [0.3];
[p,resnorm,~,exitflag,output,lambda] = lsqcurvefit(@myexternal,p0,xdata,ydata)
Interesting to note that if I replace in the function myexternal() the line "y=data{1};" by "y=p*xdata.*xdata" everything works fine. I also compared the numbers in the computed array y in both cases and it contains the same values.
Do you have any help what might be the mistake? Help is highly appreciated: :-)
Maik