MathGroup Archive 2001

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

Search the Archive

Re: Fitting data

  • To: mathgroup at smc.vnet.net
  • Subject: [mg29587] Re: Fitting data
  • From: Tom Burton <tburton at cts.com>
  • Date: Wed, 27 Jun 2001 05:12:22 -0400 (EDT)
  • Organization: Brahea Consulting
  • References: <9h401r$4a6$1@smc.vnet.net> <9h8m2v$qsi$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On Tue, 26 Jun 2001 00:47:27 +0000 (UTC), in comp.soft-sys.math.mathematica you wrote:

>An normal distibution wasn't a good example.
>
>What if I collected data from an experiment that I modeled by (for example):
>
>u(t)= a1 * sin(a2*t) + a3*exp(a4^3).
>
>How can I find a1, a2, a3 and a4 so that my function fits the data as good
>as possible?

In[88]:=
Needs["Statistics`NonlinearFit`"]

Given a model similar to the one you suggested,
In[89]:=
model = a0 + a1*Sin[a2*t] + a3*Exp[a4*t^3]
Out[89]=
             3
         a4 t
a0 + a3 E      + a1 Sin[a2 t]

suppose that the data consists of a structure,
In[90]:=
structure = model /. 
   {a0 -> -1, a1 -> 3, a2 -> 4, a3 -> -1, a4 -> 2, 
    t -> i/100}
Out[90]=
       3
      i /500000         i
-1 - E          + 3 Sin[--]
                        25

embedded in noise:

In[91]:=
data = Table[{i/100, structure + Random[]}, {i, 0, 100}]; 

Then NonlinearRegress will return the fitted parameters:

In[92]:=
f = BestFitParameters /. NonlinearRegress[data, 
   model, t, {a0, a1, a2, a3, a4}]
FindMinimum::fmlim: 
   The minimum could not be bracketed in 
    30 iterations.
Out[92]=
{a0 -> 4.79837, a1 -> -3.02461, 
 
  a2 -> -3.63283, a3 -> -6.23785, 
 
  a4 -> 0.728969}

The fitted parameters differ greatly from the structure. This deviation suggests that the model is not well constructed. Anyway, NonlinearFit will both compute and plug the fitted parameters into the model:
In[93]:=
f = NonlinearFit[data, 
   model, t, 
   {a0, a1, a2, a3, a4}]
FindMinimum::fmlim: 
   The minimum could not be bracketed in 
    30 iterations.
Out[93]=
                             3
                   0.728969 t
4.79837 - 6.23785 E            + 
 
  3.02461 Sin[3.63283 t]

In[94]:=
Needs["Graphics`Graphics`"]
In[95]:=
DisplayTogether[
   ListPlot[data, PlotRange -> All], 
   Plot[f, {t, 0, 1}]
]; 

<graph deleted>
Tom


  • Prev by Date: Re: overlay imported picture with Mathatmatica calc
  • Next by Date: AW: Matching on Arguments of Flat Functions ...
  • Previous by thread: Re: Fitting data
  • Next by thread: Re: Fitting data