<br><br><div class="gmail_quote">On Tue, Nov 20, 2012 at 12:30 PM, Neal Becker <span dir="ltr"><<a href="mailto:ndbecker2@gmail.com" target="_blank">ndbecker2@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">Pauli Virtanen wrote:<br>
<br>
> 20.11.2012 21:11, Neal Becker kirjoitti:<br>
>> import numpy as np<br>
>> import matplotlib.pyplot as plt<br>
>><br>
>> ibo = np.array ((12, 14, 16, 18, 20, 22, 24, 26, 28, 29, 29.8, 30.2))<br>
>> gain_deriv = np.array ((0, 0,  0,  0,   0, 0,  .2, .4, .5, .5, 0,    -2))<br>
>><br>
>> import scipy.interpolate<br>
>> s = scipy.interpolate.UnivariateSpline(ibo, gain_deriv, s=0.1)<br>
>><br>
>> xs = linspace(12, 31, 100)<br>
>> gain = np.vectorize (lambda x: s.integral (12, x)) (xs)<br>
>><br>
>> plot (xs, s(xs))<br>
>> plot (xs, gain)<br>
><br>
>>From fitpack/splint.f:<br>
><br>
> c           s(x) is considered to be identically zero outside<br>
> c           the interval (t(k+1),t(n-k)).<br>
><br>
> Not documented in the Python wrapper, though.<br>
><br>
<br>
</div>Ah, thanks!  Bitten one more by the fact that spline is not meant for<br>
extrapolation, which here I had done inadvertantly.<br>
<br>
IMO, if spline isn't intended to be used to extrapolate, I'd prefer it to throw.<br></blockquote><div><br>That can be tricky at the ends due to round off errors. I added a flag to splev for this back when:<br><br>
outine splev evaluates in a number of points x(i),i=1,2,...,m<br>c  a spline s(x) of degree k, given in its b-spline representation.<br>c<br>c  calling sequence:<br>c     call splev(t,n,c,k,x,y,m,e,ier)<br>c<br>c  input parameters:<br>
c    t    : array,length n, which contains the position of the knots.<br>c    n    : integer, giving the total number of knots of s(x).<br>c    c    : array,length n, which contains the b-spline coefficients.<br>c    k    : integer, giving the degree of s(x).<br>
c    x    : array,length m, which contains the points where s(x) must<br>c           be evaluated.<br>c    m    : integer, giving the number of points where s(x) must be<br>c           evaluated.<br>c    e    : integer, if 0 the spline is extrapolated from the end<br>
c           spans for points not in the support, if 1 the spline<br>c           evaluates to zero for those points, and if 2 ier is set to<br>c           1 and the subroutine returns.<br> <br><br>Chuck<br></div><br></div>