problem = createOptimProblem('lsqcurvefit',...
'objective',model, 'xdata', t, 'ydata', F,'x0',x0,...
'lb', [0 0 -3000 -4000 0 -5],...
'ub', [10 50 3000 5000 800 5],...
'options',optimset('OutputFcn',@PlotIterates))
I want to see a plot every iteration showing the curve fitt obtained. Like in this exemple:
http://www.mathworks.com/products/demos/global-optimization/multistartWebDemo/
However I was not able to do this:
The PlotIterates function is something like this:
stop = PlotIterates (x, optimValues, state)
and the function F that I want to plot is this
F= exp(-x(1).*xdata).*(x(3).*cos(x(2).*xdata)+x(4).*sin(x(2).*xdata))+ x(6).*xdata + x(5);
plot(xdata,F,'b')
How can I get xdata to be able to plot? Please help...
You need to pass the xdata into the PlotIterates function. Change the definition of PlotIterates to look like this:
function stop = PlotIterates (x, optimValues, state, xdata)
...
Then change the call to this (an anonymous function):
myOutputFcn = @(x,optimValues,state) PlotIterates (x, optimValues, state, xdata)
problem = createOptimProblem('lsqcurvefit',...
'objective',model, 'xdata', t, 'ydata', F,'x0',x0,...
'lb', [0 0 -3000 -4000 0 -5],...
'ub', [10 50 3000 5000 800 5],...
'options',optimset('OutputFcn',myOutputFcn))
I get this error
??? Error using ==> createOptimProblem at 92
Arguments must occur in name-value pairs.
You'll have to check out your PlotFcn or OutputFcn to be sure that it works.