lsqcurvefit - problem with number of iterations

조회 수: 18(최근 30일)
Alexandra
Alexandra 2013년 10월 7일
댓글: Alexandra 2013년 10월 8일
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

채택된 답변

Alan Weiss
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.
Alan Weiss
MATLAB mathematical toolbox documentation
  댓글 수: 1
Alexandra
Alexandra 2013년 10월 8일
편집: Alexandra 2013년 10월 8일
Thank you for your response - it has proved very helpful!

댓글을 달려면 로그인하십시오.

추가 답변(1개)

A Jenkins
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:

범주

Find more on Manual Performance Optimization in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by