[Numpy-discussion] confused about univaritespline
Charles R Harris
charlesr.harris at gmail.com
Tue Nov 20 17:29:27 EST 2012
On Tue, Nov 20, 2012 at 12:30 PM, Neal Becker <ndbecker2 at gmail.com> wrote:
> Pauli Virtanen wrote:
> > 20.11.2012 21:11, Neal Becker kirjoitti:
> >> import numpy as np
> >> import matplotlib.pyplot as plt
> >> ibo = np.array ((12, 14, 16, 18, 20, 22, 24, 26, 28, 29, 29.8, 30.2))
> >> gain_deriv = np.array ((0, 0, 0, 0, 0, 0, .2, .4, .5, .5, 0,
> >> import scipy.interpolate
> >> s = scipy.interpolate.UnivariateSpline(ibo, gain_deriv, s=0.1)
> >> xs = linspace(12, 31, 100)
> >> gain = np.vectorize (lambda x: s.integral (12, x)) (xs)
> >> plot (xs, s(xs))
> >> plot (xs, gain)
> >>From fitpack/splint.f:
> > c s(x) is considered to be identically zero outside
> > c the interval (t(k+1),t(n-k)).
> > Not documented in the Python wrapper, though.
> Ah, thanks! Bitten one more by the fact that spline is not meant for
> extrapolation, which here I had done inadvertantly.
> IMO, if spline isn't intended to be used to extrapolate, I'd prefer it to
That can be tricky at the ends due to round off errors. I added a flag to
splev for this back when:
outine splev evaluates in a number of points x(i),i=1,2,...,m
c a spline s(x) of degree k, given in its b-spline representation.
c calling sequence:
c call splev(t,n,c,k,x,y,m,e,ier)
c input parameters:
c t : array,length n, which contains the position of the knots.
c n : integer, giving the total number of knots of s(x).
c c : array,length n, which contains the b-spline coefficients.
c k : integer, giving the degree of s(x).
c x : array,length m, which contains the points where s(x) must
c be evaluated.
c m : integer, giving the number of points where s(x) must be
c e : integer, if 0 the spline is extrapolated from the end
c spans for points not in the support, if 1 the spline
c evaluates to zero for those points, and if 2 ier is set to
c 1 and the subroutine returns.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion