Getting complex values for fitting parameters using nlinfit. Can anyone explain the reason why?

9 ビュー (過去 30 日間)
Hello everyone,
I am using the attached script to fit some data. All the input data for "nlinfit" are real numbers but the fitting is yielding complex variables even though the imaginary part of the complex number is 0.000i. Can anyone explain how to get real numbers from this script?
P.S. I've seen some of the answers suggesting to check if there's negative input values that might cause this problem. I'm fairly certain I do not have any negative input values.

採用された回答

David Goodmanson
David Goodmanson 2018 年 7 月 30 日
Hi Anik,
In the Ag case, the initial values are b0_ag=[5 1.5 1.5]
Take the first value of Stress_silver, Stress_silver = 1.5012771392081736
The initial value of z_ag is
z_ag = b0_ag(1).*(1-Stress_silver./b0_ag(3)).^b0_ag(2);
The expression (1 - ....) is negative and is being taken to the 1.5 power, so you get a complex answer. There are other cases as well. In the case of ni, as soon as b_ni(2) changes from its initial value b0_ni(2) = 2 to, say 2.01, the result is complex.
  1 件のコメント
Anik Faisal
Anik Faisal 2018 年 7 月 30 日
Thanks David! I get your point. I'll make sure the initial values are properly selected now. Appreciate it

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by