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: [mg31102] RE: [mg31091] Can Fit give function coefficients?
  • From: "Higinio Ramos" <higra at usal.es>
  • Date: Wed, 10 Oct 2001 03:43:13 -0400 (EDT)
  • Organization: usal
  • References: <200110090555.BAA11594@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

----- Original Message -----
From: Brett Patterson <bap at roe.ac.uk>
To: mathgroup at smc.vnet.net
Subject: [mg31102] [mg31091] Can Fit give function coefficients?


> 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?
>
> Regards,
> Brett Patterson
>
>
A way to obtain the coefficients:
In[22]:=
f1[x_] := 2 x^2;
f2[x_] := 3 x^3;

In[23]:=
data = Table[{x, 2x^3 + Random[]}, {x, 1, 8}]

Out[23]=
{{1, 2.68178}, {2, 16.3117}, {3, 54.4052}, {4, 128.953}, {5, 250.484}, {6,
    432.886}, {7, 686.642}, {8, 1024.92}}

In[24]:=
 pol = Fit[data, {1, f1[x], f2[x]}, x]

Out[24]=
\!\(\(\(0.4985852287723844`\)\(\[InvisibleSpace]\)\) +
    0.008764522745501324`\ x\^2 + 1.999615528633464`\ x\^3\)

In[25]:=
ecu = CoefficientList[pol, x] - CoefficientList[a2 + b2 f1[x] + c2 f2[x], x]
==
     0

Out[25]=
{0.498585\[InvisibleSpace] - a2, 0, 0.00876452\[InvisibleSpace] - 2 b2,
    1.99962\[InvisibleSpace] - 3 c2} == 0

In[26]:=
Solve[ecu, {a2, b2, c2}]

Out[26]=
{{a2 -> 0.498585, b2 -> 0.00438226, c2 -> 0.666539}}

Higinio



  • Prev by Date: Re: Multiple scales for Y axis of plot?
  • Next by Date: RE: Multiple scales for Y axis of plot?
  • Previous by thread: Can Fit give function coefficients?
  • Next by thread: Re: Can Fit give function coefficients?