MathGroup Archive 2005

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

Search the Archive

RE: Coefficients from Fit as a list?


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?