Re: Fit data with range
- To: mathgroup at smc.vnet.net
- Subject: [mg88411] Re: [mg88364] Fit data with range
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Mon, 5 May 2008 06:09:57 -0400 (EDT)
- Reply-to: hanlonr at cox.net
data = Table[{x, x^2 - 11 x + 24 + 6 RandomReal[]}, {x, 0, 10, .25}]; pltRng = {{0, 10}, 1.2 {Min[data[[All, 2]]], Max[data[[All, 2]]]}}; fit = Fit[data, {1, x, x^2}, x] xmin = 4; xmax = 7; fit2 = Fit[Select[data, xmin <= #[[1]] <= xmax &], {1, x, x^2}, x] Plot[{fit, fit2}, {x, 0, 10}, PlotStyle -> {Green, Blue}, Epilog -> {Red, Point[data]}, PlotRange -> pltRng] Bob Hanlon ---- Ivan <darknails at gmail.com> wrote: > Hi > > 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}] > > > > thanks! >