lsqcurvefit - problem with number of iterations
조회 수: 18(최근 30일)
I have experimental data "xdata" and "ydata" and am trying to fit a model simulated "y" (using simulink) to my data -- by using lsqcurvefit.
My problem is simply that my output shows 0 iterations because my initial guess is at a local minima. But when I use a drastically ridiculous initial guess I have 1 iteration and a ridiculous fit. I have played around with initial guesses and am getting the same thing over and over - either 1 iteration or 0.
I would greatly appreciate any advice.
Please see below for my code:
xdata = dataTime(:,1);
ydata = dataTime(:,2);
options = optimset('lsqcurvefit');
options.Algorithm = ('levenberg-marquardt');
options.MaxIter = 1e9;
options.TolFun = 1e-8;
x0 = [6, 13500, 0.00016, 28, 0.6, 1, 1, 0.1,0.02,0.25];
[x,resnorm,residual,exitflag,output] = lsqcurvefit(@myfunc,x0,xdata,ydata,,,options);
function F = myfunc(params,xdata)
gv1=params(5); gv1s=num2str(gv1); set_param('LNM/Gain1','Gain',gv1s);
gv2=params(6); gv2s=num2str(gv2); set_param('LNM/Gain2','Gain',gv2s);
gv3=params(7); gv3s=num2str(gv3); set_param('LNM/Gain3','Gain',gv3s);
[t, xhat, y] = sim('LNM');
F = y;
Alan Weiss 2013년 10월 8일
You are trying to optimize a simulation. This has its own peculiar difficulties, addressed in the documentation here. For your problem, it is clear you need to increase FinDiffRelStep or DiffMinChange. Other suggestions in the documentation might help, too.
MATLAB mathematical toolbox documentation
A Jenkins 2013년 10월 7일
1) As a first try, I'd recommend scaling your x0, so they are all similar order of magnitude when passed into lsqcurvefit().
x0 = [6, 13.5, 16, 28, 6, 1, 1, 1, 2, 25];
You can divide back out by the scale factors inside myfunc(), so you pass the right scaled values to your simulink model. The optimizer works by adding "a little bit" to each and re-running to take a deriviative near your point, but with such a large difference between the magnitudes of your numbers, it might not know how much "a little bit" is.
2) Next I'd take a look at:
The exit flag will attempt to describe why it stopped iterating. Share the results here if you need more help.
3) Also look here for more tips: