Re: Using Fit to interpolate data
- To: mathgroup at smc.vnet.net
- Subject: [mg127437] Re: Using Fit to interpolate data
- From: Bill Rowe <readnews at sbcglobal.net>
- Date: Wed, 25 Jul 2012 02:31:15 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: mathgroup-newout@smc.vnet.net
- Delivered-to: mathgroup-newsend@smc.vnet.net
On 7/24/12 at 4:15 AM, carlsonkw at gmail.com (Kris Carlson) wrote: >Can someone enlighten me about how to fit a curve to data? These >data are of the density of axons of given diameters in the spinal >cord. The density of smaller fibers is dramatically larger than that >of larger fibers. There cannot be density < 0 of any diameter, so >heuristically to prevent a fit yielding an equation that dips below >0 I added an end point with fiber diameter = 16 that is 0. Then >using Fit I try to increase the exponent of x until the curve >doesn't yield negative values. The fit looks good in large scale but >when I plot the region of greatest interest, 8 < x < 14, it no >longer looks so good. Maybe I am simply ignorant about fitting a >curve to somewhat irregular data? Or can it be done? >fiberDataDensitiesFeierabend = {{16, 0}, {10.7, 0.11}, {10.4, >0.19}, {9.77, 0.41}, {8.29, 3.05}, {7.14, 19.86}}; >fbddPlot = >ListPlot[fiberDataDensitiesFeierabend, PlotMarkers -> {Automatic, >Medium}] The plot above suggests an exponential model. And doing ListLogPlot[fiberDataDensitiesFeierabend] Seems to confirm this in that the data points seem to line along a line in log space. >fbddFit = Fit[fiberDataDensitiesFeierabend, {1, x, x^-13}, x] Better to use FindFit rather than Fit. Among other things, FindFit allows you to specify constraints on the model parameters. Also, using high powers of x as basis functions is not a good idea. If you absolutely must get a polynomial fit, choose Chebyshev polynomials or Legendre polynomials as your basis functions rather than powers of x. Using FindFit and assuming an exponential model I get: In[12]:= params=FindFit[fiberDataDensitiesFeierabend, a Exp[b x], {a, b}, x] Out[12]= {a->2.06978*10^6,b->-1.61827} and Plot[a Exp[b x] /. params, {x, 7, 16.5}, Epilog -> {PointSize[.02], Point[fiberDataDensitiesFeierabend]}] suggests this is a reasonable fit to the data.