Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: How to Calculatelength of an Spline

  • To: mathgroup at smc.vnet.net
  • Subject: [mg104878] Re: [mg104840] Re: [mg104819] How to Calculatelength of an Spline
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Thu, 12 Nov 2009 06:05:19 -0500 (EST)
  • References: <200911101104.GAA20038@smc.vnet.net>
  • Reply-to: drmajorbob at yahoo.com

There's a serious bug in Plot, I think.

I get the same kernel crash with NIntegrate as you, and I also get a blank  
plot (no crash) with

data = Table[{n, Fibonacci[n]}, {n, 1, 10}];
sp = Interpolation[data, Method -> "Spline"];
Plot[sp@x, {n, 1, 10}, PlotRange -> All]

even though there's no problem here:

Table[sp@x, {x, 1, 10, .1}]

{1., 0.908603, 0.841858, 0.798136, 0.77581, 0.773252, 0.788834, \
0.820928, 0.867905, 0.928139, 1., 1.08186, 1.17209, 1.26907, 1.37117, \
1.47675, 1.58419, 1.69186, 1.79814, 1.9014, 2., 2.09295, 2.18176, \
2.26857, 2.35553, 2.44476, 2.53841, 2.63862, 2.74753, 2.86727, 3., \
3.14733, 3.30885, 3.48363, 3.67073, 3.86922, 4.07818, 4.29667, \
4.52375, 4.75851, 5., 5.24772, 5.50282, 5.76691, 6.04155, 6.32835, \
6.62887, 6.94471, 7.27746, 7.62869, 8., 8.3928, 8.80785, 9.24574, \
9.70706, 10.1924, 10.7023, 11.2375, 11.7984, 12.3857, 13., 13.6421, \
14.3138, 15.0171, 15.7542, 16.5271, 17.3378, 18.1884, 19.0809, \
20.0174, 21., 22.0309, 23.1131, 24.2497, 25.4441, 26.6993, 28.0186, \
29.4051, 30.862, 32.3926, 34., 35.6874, 37.458, 39.3149, 41.2614, \
43.3007, 45.4359, 47.6703, 50.0069, 52.4491, 55.}

or here:

Table[sp'@x, {x, 1, 10, .1}]

{-1.04265, -0.787998, -0.549621, -0.327524, -0.121706, 0.0678318, \
0.24109, 0.398069, 0.538768, 0.663187, 0.771327, 0.863187, 0.938768, \
0.998069, 1.04109, 1.06783, 1.07829, 1.07248, 1.05038, 1.012, \
0.957346, 0.905248, 0.874549, 0.865248, 0.877346, 0.910841, 0.965735, \
1.04203, 1.13972, 1.2588, 1.39929, 1.54582, 1.68303, 1.81094, \
1.92953, 2.0388, 2.13877, 2.22942, 2.31076, 2.38278, 2.44549, \
2.51148, 2.59331, 2.691, 2.80455, 2.93394, 3.07919, 3.2403, 3.41726, \
3.61007, 3.81873, 4.03827, 4.26371, 4.49505, 4.73229, 4.97542, \
5.22446, 5.47939, 5.74022, 6.00695, 6.27957, 6.56542, 6.87183, \
7.19879, 7.5463, 7.91436, 8.30298, 8.71215, 9.14187, 9.59215, 10.063, \
10.56, 11.089, 11.6498, 12.2425, 12.8671, 13.5236, 14.212, 14.9323, \
15.6845, 16.4685, 17.2845, 18.1323, 19.012, 19.9236, 20.8671, \
21.8425, 22.8498, 23.889, 24.96, 26.063}

Your fix doesn't remedy plots, either:

spn[x_?NumericQ] = sp@x;
spp[x_?NumericQ] = sp'[x];
Plot[spn@x, {n, 1, 10}, PlotRange -> All]
Plot[spp@x, {n, 1, 10}, PlotRange -> All]

(Both plots show axes but no curve.)

Bobby

On Wed, 11 Nov 2009 03:29:12 -0600, Mark McClure <mcmcclur at unca.edu> wrote:

> On Tue, Nov 10, 2009 at 6:04 AM, alfaeco <alfaeco at gmail.com> wrote:
>> Given an Interpolating function with method-> Spline.
>> sp = Interpolation[tbl, Method -> "Spline"];
>> How can I calculate the distance between two arbitrary points of the
>> splines?
>
> I assume you mean length along the curve as measured
> by the standard calculus formula:
> Integrate[Sqrt[1+f'[x]^2], {x,a,b}]
>
> I actually noticed something that appears to be a
> little bug to me in this problem.  The following
> crashes my kernel, but it should work just fine:
>
> data = Table[Fibonacci[n], {n, 1, 10}];
> sp = Interpolation[data,  Method -> "Spline"];
> NIntegrate[Sqrt[1 + sp'[x]^2], {x, 1, 10}]
>
>
> Note that it does work just fine, if you remove
> the Method -> "Spline" option.  Presumably, some
> sort of problem arises when NIntegrate attempts
> some preprocessing of the integrand involving a
> Spline.  We can get around this like so:
>
> data = Table[Fibonacci[n], {n, 1, 10}];
> sp = Interpolation[data, Method -> "Spline"];
> spp[x_?NumericQ] := sp'[x];
> NIntegrate[Sqrt[1 + spp[x]^2], {x, 1, 10}]
>
> Mark McClure
>


-- 
DrMajorBob at yahoo.com


  • Prev by Date: Re: Another NMinimize w/ NDSolve question...
  • Next by Date: mathematica 7.0 crash with 3d Graphics
  • Previous by thread: Re: Re: How to Calculatelength of an Spline
  • Next by thread: Re: How to Calculatelength of an Spline curve between two points?