bad fit with lsqnonlin LM
6 ビュー (過去 30 日間)
古いコメントを表示
I am trying to create a solver that will fit the following. Y data has been normalised to 1.
param0 = 0;
opts = optimset('lsqnonlin'); % method
opts.Algorithm = 'levenberg-marquardt';
opts.Display = 'iter';
TR=0.0055
Xk = [0.0785398163397448 0.165806278939461 0.235619449019234 0.270526034059121 0.523598775598299];
Yk = [0.451237263464338 0.810771470160116 0.965065502183406 1 0.991266375545852]
modelfun = @(a) ((1-exp(-TR/a))*sin(Xk)) ./ (1-cos(Xk)*exp(-TR/a)) - Yk;
[estcoefs,resnorm,residual,exitflag,output] = lsqnonlin(modelfun,param0,[],[],opts);
I am getting unrealistic values from using lsqnonlin. For this data, I know the result should be 0.08. This can be verified if I put 0.08 into the model and compare with the data.
plot(Xk,Yk,'b')
plot(Xk,((modelfun(estcoefs))+Yk)/max(modelfun(estcoefs)+Yk),'r');
plot(Xk,(modelfun(0.08)+Yk)/max(modelfun(0.08)+Yk),'g')
Can anyone help me with this issue?
0 件のコメント
採用された回答
Matt J
2018 年 7 月 17 日
編集済み: Matt J
2018 年 7 月 17 日
Your criterion for a good fit is quite strange. Regardless, lsqnonlin uses a least squares fitting criterion and, with respect to that criterion, lsqnonlin has succeeded in giving you a superior solution:
>> norm(modelfun(estcoefs))
ans =
1.3673
>> norm(modelfun(.08))
ans =
1.6047
3 件のコメント
Matt J
2018 年 7 月 18 日
編集済み: Matt J
2018 年 7 月 18 日
I would expect regardless the initial parameters, it would try give a superior fit.
It always tries, but can fail, depending on the quality of your initial guess.
In any case, a(2)=0 is not a legal guess, because it will cause divide-by-zero operations TR/a in your modelfun().
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!