MathGroup Archive 2004

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

Search the Archive

Re: Re: 'NonlinearFit` confusion

  • To: mathgroup at smc.vnet.net
  • Subject: [mg49972] Re: [mg49895] Re: [mg49844] 'NonlinearFit` confusion
  • From: Yasvir Tesiram <tesiramy at omrf.ouhsc.edu>
  • Date: Sun, 8 Aug 2004 05:38:01 -0400 (EDT)
  • References: <200408041446.KAA20105@smc.vnet.net> <200408051321.JAA05885@smc.vnet.net> <6.1.2.0.1.20040807114330.04939518@pop.hfx.eastlink.ca>
  • Sender: owner-wri-mathgroup at wolfram.com

G'day,
Yes, but I have no idea what multi-extremality means in English. You can
use FindFit as well. But here, one just needs to take a good look at the
model function to quickly realise where the sample points should be and
how many.
It is always an assumption by most that when fitting data that more
points are better. And its usually forgotten that all you need
are sufficient data points to smoothly sample the model function.
Obviously in this case the model function can be smoothly sampled through
a single period. Perhaps that in itself is too much.
I think Dr Bob has already pointed out something about fitting, non-exact
and science. Which leaves the physical intepretation of the function used
to model the data!
You may have also noticed that I didn't skip data points. I simple took
the first 40 or so.

Best Regards
Yas


 On Sat, 7 Aug 2004, Janos D. Pinter wrote:

>
> Yas,
>
> skipping some of the data will not eliminate the potential
> multi-extremality of a nonlinear model-fitting problem (but can make the
> solution less stable). As Paul Abbott noted, either one needs a
> 'sufficiently good' starting point for successful local
> fitting/optimization, or needs to apply global optimization methods to find
> the best numerical fit.
>
> Regards,
> Janos Pinter
>
>
> At 10:21 AM 8/5/2004, you wrote:
> >Hi,
> >
> >Why not take less points, rather than more??
> >
> >In[480]:=
> >Clear[datay,datax,data1]
> >datay = Table [6 + 2Sin[3 + x], {x, -10Pi, 10Pi, 0.05}];
> >datax = Table [x, {x, -10Pi, 10Pi, 0.05}];
> >data1 = Table[{datax[[i]], datay[[i]]}, {i, 1, Length[datay]}];
> >Length[data1]
> >First[data1]
> >
> >Out[484]=
> >1257
> >
> >Out[485]=
> >{-31.4159,6.28224}
> >
> >In[511]:=
> >Clear[a,b,c,d,e]
> >sinFit1=NonlinearFit[Take[data1,40], c + a *Sin[d + e *x], x, {a, c,
> >d,e}]
> >
> >Out[512]=
> >6.\[InvisibleSpace]+2. Sin[3.\[InvisibleSpace]+1. x]
> >
> >
> >In[513]:=
> >Clear[y,datay,datax,a,b,c,d,e]
> >datay = Table [6 + 2Sin[3 + 5 x], {x, -10Pi, 10Pi, 0.05}];
> >datax = Table [x, {x, -10Pi, 10Pi, 0.05}];
> >data2 = Table[{datax[[i]], datay[[i]]}, {i, 1, Length[datay]}];
> >Length[data2]
> >First[data2]
> >
> >Out[517]=
> >1257
> >
> >Out[518]=
> >{-31.4159,6.28224}
> >
> >In[519]:=
> >y=a*Sin[d+e x]+c;
> >sinFit2=NonlinearFit[Take[data2,40],y, x, {a,c, d,e}]
> >
> >Out[520]=
> >6.\[InvisibleSpace]+2. Sin[122.381\[InvisibleSpace]+5. x]
> >
> >
> >DisplayTogether[
> >    Plot[sinFit1, {x, -10Pi, -8 Pi}, PlotStyle -> Blue],
> >    Plot[sinFit2, {x, -10Pi, -8 Pi}, PlotStyle -> Red],
> >
> >    ListPlot[Take[data1, 40], PlotStyle -> {Blue, PointSize[0.011]}],
> >    ListPlot[Take[data2, 30], PlotStyle -> {Red, PointSize[0.011]}],
> >    Prolog -> {
> >        {
> >          Blue,
> >          Text["sinFit1", {-27.5, 7}, {-1, 0},
> >            TextStyle -> {FontFamily -> "Times",
> >                FontWeight -> "Bold",
> >                FontSize -> 18
> >                }
> >            ]
> >          },
> >
> >        {
> >          Red,
> >          Text["sinFit2", {-26.9, 6}, {-1, 0},
> >            TextStyle -> {FontFamily -> "Times",
> >                FontWeight -> "Bold",
> >                FontSize -> 18
> >                }
> >            ]
> >          }
> >        },
> >    ImageSize -> 800,
> >    Frame -> False,
> >    AxesOrigin -> {-31.5, 4.0}
> >
> >    ]
> >
> >Cheers
> >Yas
> >
> >
> >
> >On Aug 4, 2004, at 9:46 AM, Klingot wrote:
> >
> > > I'm trying to fit a sinusoidal function to my data using
> > > 'NonlinearFit' but it's exhibiting rather odd behaviour. Please see my
> > > examples below:
> > >
> > > EXAMPLE (1).
> > >
> > > **** As a test, I created a list of data from a function of the form y
> > > = 6 + 2Sin[3 + x] with:
> > >
> > > datay = Table [6 + 2Sin[3 + x], {x, -10Pi, 10Pi, 0.05}];
> > > datax = Table [x, {x, -10Pi, 10Pi, 0.05}];
> > > data = Table[{datax[[i]], datay[[i]]}, {i, 1, Length[datay]}];
> > >
> > > **** Then tested to see whether NonlinearFit would correctly deduce
> > > the equations parameters with:
> > >
> > > NonlinearFit[data, c + a Sin[d + e x], x, {a, c, d,e}]
> > >
> > > **** As expected, it gave me '6.+ 2. Sin[3. + 1. x]' ... exactly as
> > > one would expect :)
> > >
> > >
> > > EXAMPLE (2).
> > >
> > > **** Second test, I modified the equation by multiplying x by 5, ie.
> > > y = 6 + 2Sin[3 + 5x]:
> > >
> > > datay = Table [6 + 2Sin[3 + 5 x], {x, -10Pi, 10Pi, 0.05}];
> > > datax = Table [x, {x, -10Pi, 10Pi, 0.05}];
> > > data = Table[{datax[[i]], datay[[i]]}, {i, 1, Length[datay]}];
> > >
> > > ***** and applied the NonlinearFit as before:
> > >
> > > NonlinearFit[data, c + a Sin[d + e x], x, {a, c, d,e}]
> > >
> > > ***** but this time I get a wildly innacurate result:    6.000165 +
> > > 0.025086 Sin[0.0080308 - 0.247967 x]
> > >
> > > Specifically, the parameters 'a', 'd' and 'e' are all completely in
> > > error by orders of magnitude.
> > >
> > > I tried extending the range of the data to include more cycles of the
> > > sinusoid, thereby making it more continuous/monotonic but that made no
> > > difference.
> > >
> > > Am I missing something fundamental here?
> > >
> > > Any assistance would be greatly appreciated.
> > >
> > > PS: I'm using Mathematica 5.0 on a MAC.
> > >
> >Dr. Yasvir A. Tesiram
> >Associate Research Scientist
> >Oklahoma Medical Research Foundation
> >Free Radical Biology and Ageing Research Program
> >825 NE 13th Street, OKC, OK, 73104
> >
> >P: (405) 271 7126
> >F: (405) 271 1795
> >E: yat at omrf.ouhsc.edu
>


  • Prev by Date: Re: Re: 'NonlinearFit` confusion
  • Next by Date: Re: Re: populate a list with random numbers from normal distribution?
  • Previous by thread: Re: Re: 'NonlinearFit` confusion
  • Next by thread: Re: Re: 'NonlinearFit` confusion