MathGroup Archive 2005

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

Search the Archive

RE: Coefficients from Fit as a list?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63420] RE: [mg63396] Coefficients from Fit as a list?
  • From: "David Annetts" <davidannetts at aapt.net.au>
  • Date: Fri, 30 Dec 2005 02:32:35 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Hi LZ,

> How can I store the coefficients from the Fit function as a list?

The easiest way is to use CoefficientList.  For example,

data = (Random[Real, {-1, 1}] + 2  # ) & /@ Range[25];
dplt = ListPlot[data, PlotJoined -> False];
ft = Fit[data, {1, x}, x]

coef = CoefficientList[ft, x]

DisplayTogether[{
      ListPlot[data, PlotJoined -> False],
      Plot[Evaluate[ft], {x, 0, 25}, PlotStyle -> Red]
      }];

Another way is to use Regress instead as this can output the coefficients as
a list anyway.  For example,

Needs["Statistics`LinearRegression`"]
Regress[data, {1, x}, x, RegressionReport -> {BestFitCoefficients, 
  SummaryReport}]

coef = BestFitParameters /. %

Regards,

Dave.


  • Prev by Date: Re: Coefficients from Fit as a list?
  • Next by Date: Re: RealValued functions and derivatives
  • Previous by thread: Re: Coefficients from Fit as a list?
  • Next by thread: Re: Coefficients from Fit as a list?