lsqnonlin with jacobian problem
2 ビュー (過去 30 日間)
古いコメントを表示
TE=2:5:5*20;
S(1,:)=104*exp(-TE/10);
options=optimset('Algorithm','levenberg-marquardt','Display','off','Jacobian ','on','Tolfun',1e-6 );
P0=[59 30];
P=lsqnonlin(@test,P0,[],[],options,S,TE)
function [F,J]=test(P,S,TE)
Ft=P(1)*exp(-TE/P(2));
F=S-Ft;
if nargout >1
J(:,1)=exp(-TE/P(2));
J(:,2)=P(1)*TE.*exp(-TE/P(2))/(P(2)^2);
end
1 件のコメント
Walter Roberson
2012 年 7 月 19 日
Are you encountering an error message? If so, what message and where?
回答 (5 件)
Walter Roberson
2012 年 7 月 19 日
lsqnonlin() accepts a maximum of 5 parameters. See http://www.mathworks.com/help/toolbox/optim/ug/lsqnonlin.html and http://www.mathworks.com/help/toolbox/optim/ug/brhkghv-7.html
0 件のコメント
Mus Bohr
2012 年 7 月 19 日
1 件のコメント
Walter Roberson
2012 年 7 月 19 日
編集済み: Walter Roberson
2012 年 7 月 19 日
P=lsqnonlin(@test,P0,[],[],options,S,TE)
- @test
- P0
- []
- []
- options
- S
- TE
That is 7 parameters. lsqnonlin() does not accept anything after "options".
Mus Bohr
2012 年 7 月 19 日
2 件のコメント
Walter Roberson
2012 年 7 月 19 日
parameters after "options" has no defined result, and so is subject to change at any time, without notice. We repeatedly get Questions here from people who have attempted to pass extra parameters in a similar manner only to have the function fail because of it. Is there a point in relying on accidental behavior when a simple and well-documented adjustment is available? http://www.mathworks.com/help/toolbox/optim/ug/brhkghv-7.html
Star Strider
2012 年 7 月 19 日
Swapping S and Ft so that F = Ft - S will likely solve your problem. In the objective function you gave it, the lsqnonlin function uses the Jacobian of F in its calculation, not the Jacobian of Ft, and while they may look the same, the derivatives of F = S - Ft will be the negative of the ones you posted, while the derivatives of F = Ft - S will have the same signs as those you posted.
This is likely the reason that with the ‘Jacobian’ option ‘off’, your function converged.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!