MathGroup Archive 2008

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

Search the Archive

Re: naive question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg92835] Re: naive question
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Tue, 14 Oct 2008 05:00:00 -0400 (EDT)

On 10/13/08 at 6:18 AM, fgutiers2002 at yahoo.com (Francisco Gutierrez)
wrote:

>Dear Friends: I am using Fit within a function, and I want it to
>produce only a list of
>coefficients, without the variables.
>For example, if I plug into fit the following:
>Fit[{{1,2,3},{4,5,6},{7,8,9}},{1,x1,x2},{x1,x2}], Mathematica
>produces: 1.55556+0.555556 x1+0.444444 x2

>I want to get only the following list: {1.55556,0.555556,0.444444}

>It seem awfully simple, but I haven't managed. How can I do it?

You could use CoefficientList to extract the coefficients as follows:

In[27]:= Flatten[
   CoefficientList[
    Fit[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, {1, x1, x2}, {x1,
x2}], {x1,
      x2}]][[{1, 3, 2}]]

Out[27]= {1.55556,0.555556,0.444444}

But I think a better approach would be to use FindFit instead of
=46it. That is,

In[28]:= {a, b, c} /.
  FindFit[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}},
   a + b x1 + c x2, {a, b, c}, {x1, x2}]

Out[28]= {1.55556,0.555556,0.444444}


  • Prev by Date: Re: Exclude O[] from Series[] for Solve[] in Mathematica
  • Next by Date: Re: naive question
  • Previous by thread: Re: naive question
  • Next by thread: Re: naive question