Re: NonlinearFit works not so good
- To: mathgroup at smc.vnet.net
- Subject: [mg49614] Re: [mg49566] NonlinearFit works not so good
- From: DrBob <drbob at bigfoot.com>
- Date: Sat, 24 Jul 2004 03:48:35 -0400 (EDT)
- References: <200407231000.GAA20471@smc.vnet.net> <opsbl30dbxiz9bcq@monster.cox-internet.com>
- Reply-to: drbob at bigfoot.com
- Sender: owner-wri-mathgroup at wolfram.com
Increasing PlotPoints helps:
Needs["Statistics`NonlinearFit`"]
Needs["Graphics`Colors`"]
f[x_]=100 Sin[3 x+1]+2;
Plot[f[x],{x,0,5},PlotPoints\[Rule]50,DisplayFunction\[Rule]Identity];
data=First@Cases[Graphics[%],Line[x___]\[RuleDelayed]x,Infinity];
Length@data
Off[FindFit::"sszero"]
Clear@g
g[x_]=NonlinearFit[data,a Sin[b x+c]+d,{x},{a,b,c,d}];
DisplayTogether[Plot[{g[
x],f[x]},{x,0,5},PlotRange\[Rule]All,PlotStyle->{Red,Blue}],ListPlot[
data]]
192
Omitting PlotPoints gives 157 points, and that's not enough!
But seventeen is enough if they're evenly spaced:
data=Table[{x,f[x]},{x,0,5,5/16}];
Length@data
Off[FindFit::"sszero"]
Clear@g
g[x_]=NonlinearFit[data,a Sin[b x+c]+d,{x},{a,b,c,d}];
DisplayTogether[Plot[{g[x],f[x]},{x,0,
5},PlotRange\[Rule]All,PlotStyle->{Red,Blue}],ListPlot[data]]
17
Bobby
On Fri, 23 Jul 2004 17:42:03 -0500, DrBob <drbob at bigfoot.com> wrote:
> The second line of code should be
>
> data = Cases[Graphics[%], Line[x___] :> x, Infinity];
>
> Bobby
>
> On Fri, 23 Jul 2004 06:00:40 -0400 (EDT), Daohua Song <ds2081 at columbia.edu> wrote:
>
>> Dear group,
>> I find the NonlinearFit give an answer far away from the truth; Here
>> is an example:
>> Plot[100 Sin[3 x+1]+2,{x,0,5}];
>> data=Cases[Graphics[%],Line[x___]?x,Infinity];
>> <<Statistics`NonlinearFit`
>> NonlinearFit[data//First,A Sin[B x+C]+D,{x},{A,B,C,D}];
>> Plot[%,{x,0,5}]
>> ListPlot[data//First]
>>
>> If i chop the +2 from above, it works fine. but The whole thing gives
>> bad fit again if you change {x,0,5}->{x,0,10}
>> So NonlinearFit also is not stable!
>> I hope it should be improved
>> Daohua
>>
>>
>>
>
>
>
--
DrBob at bigfoot.com
www.eclecticdreams.net
- References:
- NonlinearFit works not so good
- From: Daohua Song <ds2081@columbia.edu>
- NonlinearFit works not so good