MathGroup Archive 2001

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

Search the Archive

Re: Exponential fit question.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg28052] Re: Exponential fit question.
  • From: Matthias Hertel <wir95cgu at studserv.uni-leipzig.de>
  • Date: Thu, 29 Mar 2001 03:24:17 -0500 (EST)
  • References: <99pdg6$lft@smc.vnet.net> <200103280740.CAA25801@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Just in case anybody's still unsure what Fit does, here's what:

    designmatrix[data_List, funs_List, vars_List] := 
        N[funs /. MapThread[Rule, {vars, Drop[#, -1]}]] & /@ data

    myfit[data_List, funs_List, vars_List] := 
        Plus @@ ((funs*
            PseudoInverse[designmatrix[data, funs, vars]].(Last /@ data)))

This is just a bare-bones version that doesn't support all the
different ways of calling Fit, but the math is there (see for instance
_Numerical_Recipes_, 2nd ed., S15.4 "General Linear Least Squares" for
explanations).

    In[1]:= myfit[data, {Exp[x]}, {x}] == Fit[data, Exp[x], x]

    True

Doing Fit's job yourself actually makes sense if you want to fit a lot
of different data vectors to the same model. Compute the Penrose-Moore
inverse once and save it away. Then, for each data vector, just do one
matrix.vector multiplication to get the coefficients of your model
functions.

In the present case, it is also instructive to look at the design
matrix. Even if the model a*Exp[x] were a good fit for the data, we
would still not get a fit that is intuitively "right" because the last
point (with the largest x) would be approximated almost perfectly
while the other ones wouldn't matter at all. Least squares just
doesn't do what you want when the values span several orders of
magnitude (because intuitively, you're looking at relative errors,
while least squares does not). As was already pointed out, this is why
taking the logarithm and doing a linear fit would be a good idea even
if it were as simple numerically to fit a*Exp[b*x] directly.

Regards
Matthias

Ignacio Rodriguez <ignacio at sgirmn.pluri.ucm.es> writes:
> Fit will try a fit in the following way:
> 
> Fit[data,{a(x),b(x)},x] will fit data to A a(x) + B b(x), where a(x) and
> b(x) are the functions you supply and A and B are two fit parametes.
> 
> In your case, Fit[data,Exp[x],x] will fit data to A Exp[x], which is
> clearly not the case for your data.
> 
[...]
> > 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.


  • Prev by Date: Defining a flat, orderless, one-identical function?
  • Next by Date: C, MathLink or Java, J/Link
  • Previous by thread: Re: Exponential fit question.
  • Next by thread: Re: Exponential fit question.