Re: Approximation of a Function
- To: mathgroup at smc.vnet.net
- Subject: [mg33501] Re: [mg33464] Approximation of a Function
- From: BobHanlon at aol.com
- Date: Sun, 24 Mar 2002 01:43:54 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
In a message dated 3/22/02 4:48:38 AM, rezso at amalthea.elte.hu writes: >Can somebody to help me to find a solution of approximation of a function? >I have a function f[x_]:=a*x+b*x^2+c*x^3, where a,b,c are known numbers. >I >would like to find a simplier function for f, for example g[x]=c1 x^c2 >at an >given interval with specified precision. How can I find the numbers c1 >and > c2? > Use NonlinearFit Needs["Graphics`Colors`"]; Needs["Statistics`NonlinearFit`"]; Clear[a,b,c,f,g]; f[x_]:=a*x+b*x^2+c*x^3; a=5; b=7; c=1; xmin = 2; xmax=5; data = Table[{x,f[x]}, {x,xmin,xmax,(xmax-xmin)/10}]; g[x_] := Evaluate[ NonlinearFit[data, c1*x^c2, x, {c1,c2}]]; g[x] Plot[{f[x], g[x]}, {x, xmin-1, xmax+1}, PlotStyle->{Blue, Red}, Epilog->{AbsolutePointSize[4], Point/@data}]; However, for a given model you get the fit that you get. It is the best fit for that model but you cannot control the precision without changing the model. a=10; b=-6; c=1; data = Table[{x,f[x]}, {x,xmin,xmax,(xmax-xmin)/10}]; g[x_] := Evaluate[ NonlinearFit[data, c1*x^c2, x, {c1,c2}]]; g[x] Plot[{f[x], g[x]}, {x, xmin-1, xmax+1}, PlotStyle->{Blue, Red}, Epilog->{AbsolutePointSize[4], Point/@data}]; Adding a constant term to the model improves the fit g[x_] := Evaluate[ NonlinearFit[data, c3+c1*x^c2, x, {c1,c2,c3}]]; g[x] Plot[{f[x], g[x]}, {x, xmin-1, xmax+1}, PlotStyle->{Blue, Red}, Epilog->{AbsolutePointSize[4], Point/@data}]; Bob Hanlon Chantilly, VA USA