Message Boards Message Boards

0
|
1587 Views
|
3 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Problem with function Best-Fit

Hi,
I have some problems with the best fit. In particular, with fitted parameters accuracy. Below the program used:

ClearAll
end = 18*10^3

model = (
 c E^(-Kp x - (K3 Kt x)/(
   Kmeno3 + Kt)) (-E^(Kp x) Kmeno3 Kp + 
    E^(Kp x + (K3 Kt x)/(Kmeno3 + Kt)) Kmeno3 Kp + 
    E^((K3 Kt x)/(Kmeno3 + Kt)) K3 Kt - 
    E^(Kp x + (K3 Kt x)/(Kmeno3 + Kt)) K3 Kt - E^(Kp x) Kp Kt + 
    E^(Kp x + (K3 Kt x)/(Kmeno3 + Kt)) Kp Kt))/(
 Kmeno3 Kp - K3 Kt + Kp Kt)
data = ReadList["prova1.dat", {Number, Number}]
nlf = NonlinearModelFit[data, 
  model, {{c, 0.5}, {K3, 5*10^-4}, {Kmeno3, 1*10^-4}, {Kt, 
    5*10^-4}, {Kp, 5*10^-4}}, x]
Show[ListPlot[data], Plot[nlf[x], {x, 0, end}, PlotStyle -> Red], 
 Frame -> True]
Normal[nlf];
nlf["BestFitParameters"]
nlf["FitResiduals"]
ListPlot[%, Filling -> Axis]
nlf[{"BestFitParameters", "ANOVATable"}]
nlf["Properties"]

I receive the following error message:
NonlinearModelFit::sszero: The step size in the search has become less than the tolerance prescribed by the PrecisionGoal option, but the gradient is larger than the tolerance specified by the AccuracyGoal option. There is a possibility that the method has stalled at a point that is not a local minimum.
Can anyone help me. I should warn you that I am not very experienced with Mathemathica.
Thank you
PS: Attached is the mathematica program

POSTED BY: Carmelo La Rosa
3 Replies
Posted 8 months ago

That message is a "warning" rather than an "error" as you see you still get a good fit. However, the underlying reason for the warning is that your model is overparametersized. If you look at the parameter correlation matrix you see the following:

nlf["CorrelationMatrix"]

Parameter correlation matrix

The correlations for parameters Kt, K3, and Kmeno3 are all either +1 or -1 indicating that the model is overparameterized. Essentially there is just a single parameter that can be estimated among those 3 parameters:

model //. K3 Kt -> a (Kmeno3 + Kt) // FullSimplify
(* (c (a - a E^(-Kp x) + (-1 + E^(-a x)) Kp))/(a - Kp) *)

This more parsimonious model gives the exact same predictions as your original model but (likely) with fewer numerical issues. The only issue is that starting values can't be the same for a and Kp otherwise the denominator will start off as zero.

nlf2 = NonlinearModelFit[data, (c (a - a E^(-Kp x) + (-1 + E^(-a x)) Kp))/(a - Kp),
  {a, c, {Kp, 0.0001}}, x];
nlf2["BestFitParameters"]
(* {a -> 0.00500545, c -> 0.0000100002, Kp -> 0.000999561} *)
Show[ListPlot[data], 
 Plot[nlf[x], {x, 0, end}, PlotStyle -> Red, PlotRange -> All], 
 Frame -> True]

data and curve fit

POSTED BY: Jim Baldwin
POSTED BY: Carmelo La Rosa
POSTED BY: Ankit Kantheti
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract