lsqcurvefit - problem with number of iterations
显示 更早的评论
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.
Thanks!
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)
a1=params(1);
a2=params(2);
b2=params(3);
a3=params(4);
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);
Ta=params(8);
Tv=params(9);
Ti=params(10);
[t, xhat, y] = sim('LNM');
F = y;
end
采纳的回答
更多回答(1 个)
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:
[x,resnorm,residual,exitflag,output]
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:
类别
在 帮助中心 和 File Exchange 中查找有关 General Applications 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!