Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #11058 > unrolled thread
| Started by | Kris Carlson <carlsonkw@gmail.com> |
|---|---|
| First post | 2012-07-24 08:16 +0000 |
| Last post | 2012-07-26 07:36 +0000 |
| Articles | 6 — 2 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
Using Fit to interpolate data Kris Carlson <carlsonkw@gmail.com> - 2012-07-24 08:16 +0000
Re: Using Fit to interpolate data Kris Carlson <carlsonkw@gmail.com> - 2012-07-25 06:35 +0000
Re: Using Fit to interpolate data Kris Carlson <carlsonkw@gmail.com> - 2012-07-25 06:36 +0000
Re: Using Fit to interpolate data "Kevin J. McCann" <kjm@KevinMcCann.com> - 2012-07-25 06:37 +0000
Re: Using Fit to interpolate data "Kevin J. McCann" <kjm@KevinMcCann.com> - 2012-07-25 06:35 +0000
Re: Using Fit to interpolate data "Kevin J. McCann" <kjm@KevinMcCann.com> - 2012-07-26 07:36 +0000
| From | Kris Carlson <carlsonkw@gmail.com> |
|---|---|
| Date | 2012-07-24 08:16 +0000 |
| Subject | Using Fit to interpolate data |
| Message-ID | <jullkd$ptc$1@smc.vnet.net> |
Hi,
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?
Thank you.
Kris
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}]
fbddFit = Fit[fiberDataDensitiesFeierabend, {1, x, x^-13}, x]
Show[Plot[fbddFit, {x, 4, 20},
PlotRange -> {{4.5, 20}, {-0.5, 25}}], fbddPlot]
Show[Plot[fbddFit, {x, 4, 28},
PlotRange -> {{8, 16}, {-0.5, 1}}], fbddPlot]
[toc] | [next] | [standalone]
| From | Kris Carlson <carlsonkw@gmail.com> |
|---|---|
| Date | 2012-07-25 06:35 +0000 |
| Message-ID | <juo43t$18f$1@smc.vnet.net> |
| In reply to | #11058 |
On Tue, Jul 24, 2012 at 9:17 AM, Kevin J. McCann <kjm@kevinmccann.com>wrote:
> A couple of comments:
>
> 1) Fit performs a linear least squares fit; so, you initially did a
> straight line fit. Do you have any reason/theory to suggest that it should
> be so? Your data appear to suggest an exponential relationship.
>
> 2) The goodness of the fit depends on the goodness of the data set. Do you
> have error bounds on the data points?
>
> Also, you might comment on why you want to do the fit in the first place.
> For example, are you going to do subsequent calculations with the fit? Are
> the fit parameters relevant? ...
>
> Kevin
>
> On 7/24/2012 4:16 AM, Kris Carlson wrote:
>
>> Hi,
>>
>> 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?
>>
>> Thank you.
>>
>> Kris
>>
>> 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}]
>>
>> fbddFit = Fit[**fiberDataDensitiesFeierabend, {1, x, x^-13}, x]
>>
>> Show[Plot[fbddFit, {x, 4, 20},
>> PlotRange -> {{4.5, 20}, {-0.5, 25}}], fbddPlot]
>>
>> Show[Plot[fbddFit, {x, 4, 28},
>> PlotRange -> {{8, 16}, {-0.5, 1}}], fbddPlot]
>>
>>
>> Kevin, I started with a low order polynomial, not linear, then advanced
> the order to get a better fit. Today made some progress by omitting the
> other terms and just using ax^-13; so in the range I need, the following
> works pretty well. Sorry I didn't give the big picture, which is I need to
> translate (interpolate) from Feirabend's fiber diameters to another group's
> (Lee's).
In[131]:= fiberDataLeeDiameters = fiberDataLee[[All, 1]]
Out[131]= {25, 14, 12.8, 11.5, 8.7, 7.5, 5.7}
In[277]:= fbddFit = Fit[fiberDataDensitiesFeierabend, {x^-13}, x]
Out[277]= 2.4929*10^12/x^13
Kris
[toc] | [prev] | [next] | [standalone]
| From | Kris Carlson <carlsonkw@gmail.com> |
|---|---|
| Date | 2012-07-25 06:36 +0000 |
| Message-ID | <juo44r$18h$1@smc.vnet.net> |
| In reply to | #11058 |
On Tue, Jul 24, 2012 at 10:14 AM, jf.alcover <jf.alcover@gmail.com> wrote:
> Why not use FindFit and an Exp ?
>
> fbddFit = Exp[-a x + b] /. FindFit[ fiberDataDensitiesFeierabend, Exp[-a*x
> + b], {a, b}, x]
>
Aha. That is helpful. I had tried using a decay function with Fit and
couldn't get the syntax, but now I see it requires FindFit. Merci. The
power law seems to work better, tho.
In[277]:= fbddFit = Fit[fiberDataDensitiesFeierabend, {x^-13}, x]
Out[277]= 2.4929*10^12/x^13
I wish I had a larger mental library of functions to try, since for these
Mathematica functions you have to suggest a basic form. But maybe the power
law is ok in the range for which I need to interpolate and extrapolate. If
anyone knows any other Mathematica tools, please jump in.
Kris
[toc] | [prev] | [next] | [standalone]
| From | "Kevin J. McCann" <kjm@KevinMcCann.com> |
|---|---|
| Date | 2012-07-25 06:37 +0000 |
| Message-ID | <juo47m$18u$1@smc.vnet.net> |
| In reply to | #11058 |
Kris,
This is a follow up to my earlier post. If you do a plot of {x,Log[y]}
of your data. You will see a very good fit to a straight line (if you
drop the first point). This suggests that you do a nonlinear fit to an
exponential or a linear fit to the log.
Kevin
fiberDataDensitiesFeierabend = {{16, 0}, {10.7, 0.11}, {10.4,
0.19}, {9.77, 0.41}, {8.29, 3.05}, {7.14, 19.86}};
data2 = ({#[[1]], Log[#[[2]]]} &) /@ fiberDataDensitiesFeierabend
data2 = Drop[data2, 1]
p1 = ListPlot[data2, PlotRange -> All]
f[x_] = Fit[data2, {1, x}, x]
p2 = Plot[f[x], {x, 7, 11}, Epilog -> p1[[1]]]
On 7/24/2012 4:16 AM, Kris Carlson wrote:
> Hi,
>
> 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?
>
> Thank you.
>
> Kris
>
> 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}]
>
> fbddFit = Fit[fiberDataDensitiesFeierabend, {1, x, x^-13}, x]
>
> Show[Plot[fbddFit, {x, 4, 20},
> PlotRange -> {{4.5, 20}, {-0.5, 25}}], fbddPlot]
>
> Show[Plot[fbddFit, {x, 4, 28},
> PlotRange -> {{8, 16}, {-0.5, 1}}], fbddPlot]
>
>
[toc] | [prev] | [next] | [standalone]
| From | "Kevin J. McCann" <kjm@KevinMcCann.com> |
|---|---|
| Date | 2012-07-25 06:35 +0000 |
| Message-ID | <juo42u$17r$1@smc.vnet.net> |
| In reply to | #11058 |
A couple of comments:
1) Fit performs a linear least squares fit; so, you initially did a
straight line fit. Do you have any reason/theory to suggest that it
should be so? Your data appear to suggest an exponential relationship.
2) The goodness of the fit depends on the goodness of the data set. Do
you have error bounds on the data points?
Also, you might comment on why you want to do the fit in the first
place. For example, are you going to do subsequent calculations with the
fit? Are the fit parameters relevant? ...
Kevin
On 7/24/2012 4:16 AM, Kris Carlson wrote:
> Hi,
>
> 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?
>
> Thank you.
>
> Kris
>
> 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}]
>
> fbddFit = Fit[fiberDataDensitiesFeierabend, {1, x, x^-13}, x]
>
> Show[Plot[fbddFit, {x, 4, 20},
> PlotRange -> {{4.5, 20}, {-0.5, 25}}], fbddPlot]
>
> Show[Plot[fbddFit, {x, 4, 28},
> PlotRange -> {{8, 16}, {-0.5, 1}}], fbddPlot]
>
>
[toc] | [prev] | [next] | [standalone]
| From | "Kevin J. McCann" <kjm@KevinMcCann.com> |
|---|---|
| Date | 2012-07-26 07:36 +0000 |
| Message-ID | <juqs23$677$1@smc.vnet.net> |
| In reply to | #11058 |
One last go at it:
fiberDataDensitiesFeierabend = {{16, 0}, {10.7, 0.11}, {10.4,
0.19}, {9.77, 0.41}, {8.29, 3.05}, {7.14, 19.86}};
model = A Exp[-a x + b];
params = FindFit[fiberDataDensitiesFeierabend, model, {A, a, b}, x]
f[x_] = model /. params
min = Min[fiberDataDensitiesFeierabend[[All, 1]]];
max = Max[fiberDataDensitiesFeierabend[[All, 1]]];
{min, max}
p1 = ListPlot[fiberDataDensitiesFeierabend,
PlotStyle -> {Red, AbsolutePointSize[7]}, PlotRange -> All];
Plot[f[x], {x, min, max}, Epilog -> p1[[1]], Frame -> True,
FrameStyle -> AbsoluteThickness[2], GridLines -> Automatic,
PlotRange -> All,
BaseStyle -> {FontFamily -> "Arial", FontSize -> 12,
FontWeight -> Bold}
]
Cheers,
Kevin
On 7/24/2012 4:16 AM, Kris Carlson wrote:
> Hi,
>
> 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?
>
> Thank you.
>
> Kris
>
> 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}]
>
> fbddFit = Fit[fiberDataDensitiesFeierabend, {1, x, x^-13}, x]
>
> Show[Plot[fbddFit, {x, 4, 20},
> PlotRange -> {{4.5, 20}, {-0.5, 25}}], fbddPlot]
>
> Show[Plot[fbddFit, {x, 4, 28},
> PlotRange -> {{8, 16}, {-0.5, 1}}], fbddPlot]
>
>
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web