Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get derivatives from 1D interpolation

Tags:

python

scipy

Is there a way to get scipy's interp1d (in linear mode) to return the derivative at each interpolated point? I could certainly write my own 1D interpolation routine that does, but presumably scipy's is internally in C and therefore faster, and speed is already a major issue.

I am ultimately feeding a munging of the interpolated function into a multi-dimensional minimization routine, so being able to pass analytic derivatives would speed things up a lot rather than having the minimization routine try to calculate them itself. And interp1d must be calculating them internally --- so can I access them?

like image 968
jbailin Avatar asked May 18 '15 17:05

jbailin


1 Answers

Use UnivariateSpline instead of interp1d, and use the derivative method to generate the first derivative. The example at the manual page here is pretty self-explanatory.

like image 188
gg349 Avatar answered Nov 10 '22 16:11

gg349