2
$\begingroup$

I have a data list and a function being to be fitted to the data to get parameters of the function as below. I can't find the parameters a, b, c, d with different below methods. Can you help me to find the parameters?

Datafit = {{105., 0.472263}, {110., 0.665252}, {115., 0.909801}, {120., 
      1.21304}, {125., 1.58227}}

Model=Exp[a + b/x + c*x + d*x*x]

1st try

FitC = NMinimize[datafit, 
  Exp[a + b/x + c*x + d*x*x], {{a, -1.7}, {b, 
    3.57}, {c, -0.99}, {d, -3.38}}, x]
{A4, B4, C4, D4} = {a, b, c, d} /. FitC

2nd try

FitC2 = FindFit[datafit, Exp[a + b/x + c*x + d*x*x], 
  x, {{a, 10}, {b, 0}, {c, 0.99}, {d, 3.38}}]

3rd try

FitC3 = NonlinearModelFit[
   datafit, {Cox[a, b, c, d, x]}, {{a, 7}, {b, 80}, {c, 4}, {d, 1}}, 
   x, MaxIterations -> 10000];

Can you help me to find parameter a, b, c, d of the model for the given data set?

$\endgroup$
1
  • $\begingroup$ See below but I would like to make you aware that the form you have for NMinimize is not correct. You need to feed it a single function and it doesn't take starting values but does accept constraints. Try nminFunction = Total@Map[(modelFun[#[[1]]] - #[[2]])^2 &, datafit] and then NMinimize[ { nminFunction, 9 < a < 10, -900 < b < -800, -.03 < c < -.02, 0.00006 < d < 0.00008 }, {a, b, c, d}] $\endgroup$ Jun 11, 2021 at 21:37

2 Answers 2

3
$\begingroup$

If you take the logarithm of the model data and the model equation you will provide the fitting software with a simpler problem.

datafit = {{105., 0.472263}, {110., 0.665252}, {115., 
   0.909801}, {120., 1.21304}, {125., 1.58227}}

Log of the model data

datafitLog = Map[{#[[1]], Log[#[[2]]]} &, datafit]

Log of the model

logModel = a + b/x + x (c + d x)

Now attempt NonlinearModelFit

logFit = NonlinearModelFit[datafitLog, logModel, {a, b, c, d}, x]

The best fit parameters are:

logFit["BestFitParameters"]

{a -> 9.3317, b -> -882.677, c -> -0.0236506, d -> 0.0000732741}

It is easy to define a fit function:

fit[x_] := Exp[logFit[x]]

Visually the results look good

Show[
 Plot[fit[x], {x, 105, 125}, PlotStyle -> Black,
  PlotRange -> {Automatic, {0.4, 1.7}}],
 ListPlot[datafit, PlotStyle -> {PointSize[0.025], Red}]
 ]

Mathematica graphics

Note that the a, b, c and d parameters are identical to both the logModel and model.

fit2[x_] := 
 Evaluate[Exp[a + b/x + c x + d x^2] /. logFit["BestFitParameters"]]

Show[
 Plot[fit2[x], {x, 105, 125}, PlotStyle -> Black,
  PlotRange -> {Automatic, {0.4, 1.7}}],
 ListPlot[datafit, PlotStyle -> {PointSize[0.025], Blue}]
 ]

Mathematica graphics

Poor Resolution

This problem is poorly resolved. One can see this by examining the correlation matrix.

logFit["CorrelationMatrix"]

I have placed the output in a grid

Mathematica graphics

All the parameters have a correlation factor close to 1 or -1 indicating that the problem is poorly resolved.

$\endgroup$
1
  • 1
    $\begingroup$ You were too polite by not mentioning that attempting to fit 5 parameters (a, b, c, d, and error variance) with just 5 data points is just asking for trouble. Also, by taking logs one ends up with a linear model and LinearModelFit[datafitLog, {1/x, x, x^2}, x] works without the need for starting values. $\endgroup$
    – JimB
    Jun 12, 2021 at 2:50
3
$\begingroup$

The scaling of x is very poor. Try x/100instead of x and the option Method -> "NMinimize"which doesn't need startvalues.

datafit = {{105., 0.472263}, {110., 0.665252}, {115.,0.909801}, {120., 1.21304}, {125., 1.58227}}
mod = NonlinearModelFit[datafit, {Exp[a + b/x/100 + c*x/100 + d*x*x/100^2]}, { a , b , c ,d }, x, Method -> "NMinimize"]
Show[ListPlot[datafit], Plot[mod[x], {x, 105, 125}]]

enter image description here

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.