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

9 views (last 30 days)
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.

Accepted Answer

David Goodmanson
David Goodmanson on 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.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!