MathGroup Archive 2001

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

Search the Archive

Re: Can Fit give function coefficients?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg31104] Re: [mg31091] Can Fit give function coefficients?
  • From: BobHanlon at aol.com
  • Date: Wed, 10 Oct 2001 03:43:15 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

In a message dated 2001/10/9 2:19:57 AM, bap at roe.ac.uk writes:

>I have a set of functions that I wish to fit to some data.
>Is there a way to succinctly get Mathematica to give me
>the coefficients of these functions in the fit.
>
>For example, say I have
>f1[x_] := 2 x^2
>f2[x_] := 3 x^3
>
>Normally, if I say: Fit[data, {1, f1[x], f2[x]}, x]
>I get a result in the form: a1 + b1 x^2 + c1 x^3,
>but I want a result of the form: a2 + b2 f1[x] + c2 f1[x].
>In this case, a2 = a1, b2 = b1/2, and c2 = c1/3.
>
>Is this possible?
>

Needs["Statistics`NonlinearFit`"];

f1[x_] := 2*x^2;
f2[x_] := 3*x^3;

data = Module[{x}, Table[{x=Random[], 5+6*f1[x]+7*f2[x]}, {20}]];

model = a+b*f1[x]+c*f2[x];

BestFitParameters /. NonlinearRegress[data, model, x, {a,b,c}]

{a->5.,b->6.,c->7.}


Bob Hanlon
Chantilly, VA  USA


  • Prev by Date: Re: AVI-Video with Mathematica V4.2
  • Next by Date: Re: Multiple scales for Y axis of plot?
  • Previous by thread: RE: Can Fit give function coefficients?
  • Next by thread: Re: Can Fit give function coefficients?