- Do not use linear interpolation with interp1. Use 'spline' to ensure differentiability.
- Do not mess with DiffMinChange as a way of making up for non-differentiability (See 1)
- Your TolX looks suspiciously large. If the default TolX setting isn't working, it usually means it needs to be made smaller, not larger..
lsqnonlin diverge away from the optimal with increasing number of iterations
1 view (last 30 days)
Show older comments
Hi all,
The problem: I have a matlab optimization script which I use lsqnonlin and levenberg-marquardt algorithm. My problem is that as the number of iterations increase the fitting diverges far away from my experimental data in a plot even though the first order optimality and residual shows decrease in values with number of iterations . I tried to play around the 'options' inputs but to no avail. I can supply the input data if some needs it for answer. Thanks a lot in advance.
here is the script:
%%import data
fc=dlmread('fullcell15_data.txt');
ano=dlmread('negative_data.txt');
cat=dlmread('positive_data.txt');
%%initial guess
x1=-228;
x2=240;
x3=11;
x4=234;
x0=[x1,x2,x3,x4];
%%optimization
DiffMinChange=1e-3;
options=optimset('TolFun',1e-20,'TolX',1e-3,'DiffMinChange',DiffMinChange,'Display','iter','Algorithm','levenberg-marquardt','maxfunevals',1000,'maxiter',1000);
[x,resnorm,residual,exitflag]=lsqnonlin(@(x) objfun(x,cat,fc,ano),x0,LB,UB,options);
Objective function ( in a separate file)
function error=objfun(x,cat,fc,ano)
for p=1:1000
dv_dq_cat(p)=(1/x(2))*(interp1(cat(:,1),cat(:,2),((fc(p,1)-x(1))/x(2)),'linear','extrap'));
dv_dq_ano(p)=(1/x(4))*(interp1(ano(:,1),ano(:,2),((fc(p,1)-x(3))/x(4)),'linear','extrap'));
dv_dq_model(p)=dv_dq_cat(p)-dv_dq_ano(p);
dv_dq_model=dv_dq_model';
error(p)=fc(p,2)-dv_dq_model(p);
end
error=error';
end
0 Comments
Answers (1)
Matt J
on 3 Mar 2015
Edited: Matt J
on 4 Mar 2015
If the residual is shrinking, then lsqnonlin is doing its job. If the result doesn't agree with your expected plots, it likely means you have implemented the wrong objfun. Or, your initial guess is not good enough.
Beyond that, though, a few recommendations:
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!