On 22 Jan 2023, at 10:40 am, Samuel Dupree 
<sdup...@speakeasy.net<mailto:sdup...@speakeasy.net>> wrote:


I believe I know what is going on, but I don't understand why.

The line for the first derivative that failed to coincide with the points in 
the plot for the cosine is actually the interpolated first derivative scaled by 
the factor pi/180. When I multiply the interpolated values for the first 
derivative by 180/pi,  the interpolated first derivative coincides with the 
points for the cosine as expected.

What I don't understand is how the interpolator came up with the scale factor 
it did and applied it using pure numbers.

Any thoughts?

Sam Dupree.


On 1/21/23 18:04, Samuel Dupree wrote:

I'm running SciPy ver. 1.9.3 under Python ver. 3.9.15  on a Mac Pro (2019) 
desktop running Mac OSX ver. 13.1 Ventura. The problem I'm having is getting 
scipy.interpolate.pchip_interpolate to return the first derivative of a pchip 
interpolation.

The test program I'm using is given below (and attached to this note).

import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import pchip_interpolate

x_observed  = np.linspace(0.0, 360.0, 51)
y_observed  = np.sin(np.pi*x_observed/180)
dydx_observed = np.cos(np.pi*x_observed/180)

Although you are running your calculations on pure numerical values, you have 
defined the sine
as a function of x in degrees. So cosine really gives you the derivative wrt. 
(x * pi/180),
dy / d(x_observed * np.pi/180) = np.cos(np.pi*x_observed/180).

Besides, as noted in a previous post, the interpolated derivative may not 
reproduces exactly the
derivative of the interpolation, but the 180/pi factor should come solely from 
the transformation
to/from working in degrees.

Cheers,
Derek
_______________________________________________
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com

Reply via email to