MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Exponential fit question.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg28030] Re: [mg27986] Exponential fit question.
  • From: "Mark Harder" <harderm at ucs.orst.edu>
  • Date: Wed, 28 Mar 2001 02:41:04 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Joe,
    A few things:
The answer you say Excel gives you is not even close:
In[135]:=7.5 E^(.0034 136)
Out[135]=11.9091
whereas in data, {x,y}={136,597}, not {136,11.9091}!!!

Also, in the plot I include below, your data points don't really follow an
exponential very well.  You can still fit an exponential to them, of course,
but the errors of the fit will be significant.

Next, Fit[] is the wrong function to use. From the Excel answer you provide,
it seems that your fitting function is of the form A Exp[k*x], where A & k
are parameters to be determined from the fit.  While A can be determined by
linear regression, which is what Fit[] does, k is a nonlinear parameter in
the function, so you should use NonlinearFit[] to get an answer of the form
you wish:
In[130]:=
f[x_] = NonlinearFit[data, ampl Exp[k x], x, {{ampl, 5.}, {k, .01}},
    WorkingPrecision -> 20, MaxIterations -> 200]

Out[130]=
                                                0.023494841470724652075 x
26.611214882968667986 E

Setting working precision to 20 digits is probably not necessary, but I
found that the default 30 iterations was not enough, hence
MaxIterations->200, which was enough to reach a minimum of the required
precision (and accuracy, see the documentation).  Now, plot your data & both
solutions

Show[{ListPlot[data, PlotStyle -> RGBColor[1, 0, 0],
      DisplayFunction -> Identity ],
    Plot[f[x], {x, 50., 136}, PlotStyle -> RGBColor[.5, 0, .5],
      DisplayFunction -> Identity ],
    Plot[7.5*Exp[0.0034 x ], {x, 50., 136}, PlotStyle -> RGBColor[1, 0, 0],
      DisplayFunction -> Identity ]},
  DisplayFunction -> $DisplayFunction ]

(* plot not shown *)

to see that Mathematica's answer (purple curve) is at least an approximation
to your data.

To get statistics of the fit, you should use NonlinearRegress[]; see the
documentation.
-mark harder
harderm at ucs.orst.edu




-----Original Message-----
From: joe <joe at wam.umd.edu>
To: mathgroup at smc.vnet.net
Subject: [mg28030] [mg27986] Exponential fit question.


>hello.
>
>I was wondering if someone could help me with the following problem.
>
>I am trying to perform an exponential fit to the following data
>{{x,y}}
>
>data
>={{50,22},{64,62},{78,122},{93,269},{107,414},{122,507},{136,597}}
>
>Fit[data,Exp[x],x]
>
>what I get is
>
>1.94272422061017735^-63 *E^x Which is not correct.
>
>With Excel I get 7.5*E^0.0034x which is correct.
>
>How can I do this with Mathematica ?
>
>Thanks.
>-Joseph.
>
>



  • Prev by Date: Re: Exponential fit question.
  • Next by Date: Re: Problem with Mathematica fonts in pdfLaTeX
  • Previous by thread: Re: Exponential fit question.
  • Next by thread: Re: Exponential fit question.