Filter löschen
Filter löschen

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

3 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

David Goodmanson
David Goodmanson am 30 Jul. 2018
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.

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by