Re: Fit data with range

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

On 5/3/08 at 6:15 AM, darknails at gmail.com (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&),_}] or 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.