Search code examples
matlabnancurve-fittingtoolbox

MATLAB: NaN computed by model function, fitting cannot continue. Try using or tightening upper and lower bounds on coefficients


On MATLAB, I am using the Curve Fitting App to fit this model (from the Sheindorf–Rebuhn–Sheintuch "SRS"):

Q = k1*C1*(a11*C1+a12*C2)^(n1-1)

With these provided data:

% The x
C1 = [0 14.336 18.37041 35.612 48.91934 62.43846 84.19304 80.52791 98.55237 114.74732 121.88417];
% The y
C2 = [0 7.78606 18.16868 35.82219 40.7553 52.15498 58.57749 70.75204 81.02773 85.89886 94.22023];
% The z
Q = [0 35.44 44.81 47.172 55.1 59.22706 65.1487 69.83486 72.37768 75.673 85.26529];

After many attempts, I found that the fitting will not continue unless the (n1-1) >= 0, meaning n1 bounds should be from 1 to inf... which is incorrect in this case because n1 should be between 0 and 1.

Actually, this error is not logical, I mean why n1-1 must be positive? (Am I that bad at math?)

By the way, I tried this on two different versions of MATLAB (R2020a and R2022b).

Regards.

Here are some screenshots for the Fit Options:

enter image description here enter image description here


Solution

  • It is about the first element 0 presented in each input vector: C1, C2, and Q.

    Reasonable results are obtained after removing these zeros.

    And the reason why it was hard to be detected is that whenever changing the values of the C1, C2, and Q and loading them using the Select Data icon, it is a must to empty the X data, Y data, and Z data boxes each time before adding the new C1 (the X data), C2(the Y data), Q(the Z data).