Re: Fit data with range
- To: mathgroup at smc.vnet.net
- Subject: [mg88402] Re: Fit data with range
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Mon, 5 May 2008 06:08:19 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <fvhdv7$3q6$1@smc.vnet.net>
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] > > Plot[fit,{x,0,10}] You could use *Select[]* to massage your data. For instance, data = {{0, 1}, {1, 0}, {3, 2}, {5, 4}, {7, 8}, {9, 11}}; xmin = 1; xmax = 7; pts = Select[data, xmin <= #[[1]] <= xmax &] fit = Fit[pts, {1, x, x^2}, x] Show[ListPlot[pts, PlotStyle -> {Red, PointSize -> Large}], Plot[fit, {x, xmin, xmax}, PlotStyle -> {Blue, Thick}]] {{1, 0}, {3, 2}, {5, 4}, {7, 8}} 2 -0.325 + 0.3 x + 0.125 x Regards, -- Jean-Marc