Re: sampling a spline

*To*: mathgroup at smc.vnet.net*Subject*: [mg106082] Re: sampling a spline*From*: dh <dh at metrohm.com>*Date*: Fri, 1 Jan 2010 05:33:20 -0500 (EST)*References*: <hhhmdr$o0g$1@smc.vnet.net>

Hi Charles, as I undersatnd your question, you want to sample the spline at equidistant points. Short question, long answer. The reason this is not simple is that a spline is not a function, but a graphics object. Therefore, operations that are defined for functions do not work with a SplineFunction. To obtain a equidistant sampling we may re-parametrize the spline with the curve length. Toward this aim, we describe the spline by an approximating numerical function. Assume we have data and fit a spline: d = RandomReal[1, {5, 2}] sp = SplineFit[d, Cubic]; The spline is a vector function. We can approximate it ny a numerical function by: f1[t_?NumericQ] := sp[t][[1]]; f2[t_?NumericQ] := sp[t][[2]]; fun = Evaluate@{Evaluate@ FunctionInterpolation[f1[t], {t, 0, 4}, InterpolationOrder -> 4][#], Evaluate@ FunctionInterpolation[f2[t], {t, 0, 4}, InterpolationOrder -> 4][#]} &; Note that we need to increase the default order to obtain a reasonable accuracy. We can now calculate the length of the tangent in the original parametrisation. Using this we can get the curve length as a function of the original parameter: ltan = FunctionInterpolation[Norm[fun'[tt]], {tt, 0, 4}] s = FunctionInterpolation[ Integrate[ltan[ttt], {ttt, 0, tt}], {tt, 0, 4}] To obtain the original parameter as a fzunction of the curve length, we need to invert this function. W may do this using the fact that the derivative of the inverse function is the inverse of the original function: param = par /. NDSolve[{par'[x] == 1/ltan[par[x]], par[0] == 0}, par, {x, 0, s[4]}][[1]] This gives us the original parameter as a function of the curve length. Here is the whole example with a plot where the data points are black and the equidistant points are red: Needs["Splines`"]; d = RandomReal[1, {5, 2}] sp = SplineFit[d, Cubic]; f1[t_?NumericQ] := sp[t][[1]]; f2[t_?NumericQ] := sp[t][[2]]; fun = Evaluate@{Evaluate@ FunctionInterpolation[f1[t], {t, 0, 4}, InterpolationOrder -> 4][#], Evaluate@ FunctionInterpolation[f2[t], {t, 0, 4}, InterpolationOrder -> 4][#]} &; ltan = FunctionInterpolation[Norm[fun'[tt]], {tt, 0, 4}] s = FunctionInterpolation[ Integrate[ltan[ttt], {ttt, 0, tt}], {tt, 0, 4}] param = par /. NDSolve[{par'[x] == 1/ltan[par[x]], par[0] == 0}, par, {x, 0, s[4]}][[1]] ParametricPlot[fun[param[t]], {t, 0, s[4]}, Epilog -> {Red, Point[Table[sp[Min[4, Max[0, param[t]]]], {t, 0, s[4], s[4]/100}]], Black, Point[d]}] Daniel On 31 Dez., 09:12, "Hagwood, Charles R." <charles.hagw... at nist.gov> wrote: > How does one uniformly sample a spline gotten from the command SplineFit? > > Charles Hagwood