[SciPy-User] Crossing of Splines

Anne Archibald aarchiba@physics.mcgill...
Tue Jun 8 13:33:18 CDT 2010


On 8 June 2010 14:22, Marco <gaedol@gmail.com> wrote:
> Hi all!
>
> I have 2 different datasets which I fit using interpolate.splrep().
>
> I am interested in finding the point where the splines cross: as of
> now I use interpolate.splev() to evaluate each spline and then look
> for a zero in the difference of the evaluated splines.
>
> Suggestions to do it better?

It's not a wholly satisfactory solution, but if both splines were
defined on the same set of knots, you could simply subtract their
values to obtain a difference spline. There is code in
scipy.interpolate (sproot) to efficiently and reliably find the
zero(s) of a spline. The trick is making sure both splines are defined
on the same set of knots. splrep normally chooses its own set of
knots, simplifying the curve where possible, but you can supply it
with a list of knots. As long as you have roughly as many knots as
data points and they're not too awkwardly spaced you should be fine; I
think splrep starts with the list of input data points and then
deletes unnecessary knots, so you could simply supply a list of all x
values for either data set as the knots argument. You should check,
but the result should be a spline with exactly the set of knots (t in
t,c,k) that you specified. Alternatively, if you are willing to look
under the hood and interpret the t,c,k representation of the splines,
you could insert knots into that in order to obtain a common set of
knots for your two splines.

Anne

> TIA,
>
> marco
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>


More information about the SciPy-User mailing list