bad fit with lsqnonlin LM

6 ビュー (過去 30 日間)
Erin Wang
Erin Wang 2018 年 7 月 17 日
編集済み: Matt J 2018 年 7 月 18 日
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?

採用された回答

Matt J
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 件のコメント
Erin Wang
Erin Wang 2018 年 7 月 18 日
Thanks Mark! Yes indeed I did have the a(1) in there initially, but got fed up and removed it, thinking it wouldn't make a difference.
Now I put it back, and realised that it is the initial parameters that was giving the problem. If I gave a(2) an initial of 0, it would just give me 0 back. Anything that is not 0 would give me the same results ~0.083 which is what I expect. Checking the norm(modelfun(estcoefs)) found that with a(2)=0 it is around 0.7, and a(2)~0.83 it is 0.02... Excuse my naivety with the fitting algorithms and optimisations, I didn't know that it would matter this much! Is this something that comes up a lot? I would expect regardless the initial parameters, it would try give a superior fit. But in this case it didn't..
Matt J
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 件)

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by