Derivative of manipulated spline

0 votes
I am using the InterpolatedUnivariateSpline function from the scipy.interpolate library. I know that there exists a function the evaluate the derivative of the resulting spline. What I am interested in is the derivative of the log of the spline. Is there a way to calculate this directly?
Oct 8, 2018 in Python by eatcodesleeprepeat
• 4,670 points

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import InterpolatedUnivariateSpline
x = np.arange(1, 9)
y = np.sqrt(x)                                  # something to use as y-values
spl = InterpolatedUnivariateSpline(x, y)

logder = lambda x: spl.derivative()(x)/spl(x)   # derivative of log of spline

t = np.linspace(x.min(), x.max())
plt.plot(t, logder(t))


Constructing a spline based on the logarithm of data is also a reasonable approach, but it is not the same thing as the logarithm of the original spline.

if you can define a function, depending on a spline, which can be differentiated by python (analytically)

Differentiating an arbitrary function analytically is out of scope for SciPy. In the above example, I had to know that the derivative of log(x) is 1/x; SciPy does not know that. SymPy is a library for symbolic math operations such as derivatives.

It's possible to use SymPy to find the derivative of a function symbolically and then turn it, using lambdify, into a callable function that SciPy or matplotlib, etc can use.

One can also work with splines in an entirely symbolic way using SymPy but it's slow.

answered Oct 8, 2018 by Priyaj
• 56,120 points

Related Questions In Python

+2 votes
3 answers

what is the practical use of polymorphism in Python?

Polymorphism is the ability to present the ...READ MORE

answered Mar 31, 2018 in Python by anto.trigg4
• 3,420 points
+4 votes
6 answers

Use of "continue" in python

The break statement is used to "break" ...READ MORE

answered Jul 16, 2018 in Python by Omkar
• 65,820 points
+2 votes
2 answers

In a list of dictionaries, how can I find the minimum calue in a common dictionary field.

There are several options. Here is a ...READ MORE

answered Apr 10, 2018 in Python by charlie_brown
• 7,710 points
+1 vote
4 answers

Count the frequency of an item in a python list

To count the number of appearances: from collections ...READ MORE

answered Oct 18, 2018 in Python by tinitales
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
0 votes
1 answer

Derivative of manipulated spline

FlyingTeller's suggestion is probably optimal: the derivative of ...READ MORE

answered Oct 4, 2018 in Python by Priyaj
• 56,120 points
+1 vote
1 answer

How to replace id with attribute corresponding to id of another table?

Use the following query statement and let ...READ MORE

answered Aug 8, 2018 in Python by Priyaj
• 56,120 points

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.