MathGroup Archive 2008

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

Search the Archive

Re: Fit data with range

  • To: mathgroup at
  • Subject: [mg88421] Re: Fit data with range
  • From: Bill Rowe <readnews at>
  • Date: Mon, 5 May 2008 06:11:44 -0400 (EDT)

On 5/3/08 at 6:15 AM, darknails at (Ivan) wrote:

>I want to fit a polynomial function to a set of data, only between
>say xmin to xmax. How can I do that? I know only how to fit the
>whole range.

>For example:

>data = ReadList["file.dat",{Number,Number}];

>fit = Fit[data,{1,x,x^2},x]

Simply select just the points between xmin and xmax then do the
fitting. Assuming your data set consists of {x,y} pairs, then either:

Cases[data,{_?(xmin < # < xmax&),_}]


Select[data, xmin < First[#] < xmax&]

will do the selection

Note, in general it isn't a good idea to use powers of a single
variable as a set of basis functions. This will be numerically
unstable in general, becoming increasingly unstable for higher powers.

There are packages available on Wolfram's web site for doing
polynomial fits that avoid this problem.

  • Prev by Date: RE: Fit data with range
  • Next by Date: Re: Re: Axes at the origin, for 3D plots/graphs
  • Previous by thread: Re: Fit data with range
  • Next by thread: Identical elements