[SciPy-user] Finding min/max of a B-Spline

Willi Richert w.richert at gmx.net
Fri Aug 17 14:21:41 EDT 2007


Hi,

I have a sequence of n-dim points for which I approximate a spline via splrep 
and splev. For splev I can specify der=1 to get the first derivative 
evaluated. And there is sproot, which finds the roots of the originially 
created spline. However, with these methods I cannot find the roots of the 
first derivative to get the minima and maxima of the spline. How can that be 
achieved?

As an example take the 2-dim case (scipy 0.5.2):

=========================
from pylab import *
from scipy.interpolate import splrep, splev, sproot, spalde
import pylab

x=linspace(0,2*pi, 100)
y=sin(linspace(0,2*pi, 100))

rep=splrep(x, y, k=3, s=1)
ynew = splev(x, rep)

raw_points = plot(x,y)
spline_points = plot(x, ynew)

y_der = splev(x, rep, der=1)
p_der = plot(x, y_der)

# x,y_der now contain the evaluated data for the first derivative. 
# The only chance to get the root would be to again fit a polynomial 
# to the data. However, that might be overkill. What else?

legend([raw_points, spline_points, p_der],  \ 
["raw", "spline", "derivative"], "upper left")

grid()
show()
=========================

Best regards,
wr



More information about the SciPy-User mailing list