Note that there are some explanatory texts on larger screens.

plurals
  1. POSpline representation with scipy.interpolate: Poor interpolation for low-amplitude, rapidly oscillating functions
    primarykey
    data
    text
    <p>I need to (numerically) calculate the first and second derivative of a function for which I've attempted to use both <code>splrep</code> and <code>UnivariateSpline</code> to create splines for the purpose of interpolation the function to take the derivatives.</p> <p>However, it seems that there's an inherent problem in the spline representation itself for functions who's magnitude is order 10^-1 or lower <em>and</em> are (rapidly) oscillating.</p> <p>As an example, consider the following code to create a spline representation of the sine function over the interval (0,6*pi) (so the function oscillates three times only):</p> <pre><code>import scipy from scipy import interpolate import numpy from numpy import linspace import math from math import sin k = linspace(0, 6.*pi, num=10000) #interval (0,6*pi) in 10'000 steps y=[] A = 1.e0 # Amplitude of sine function for i in range(len(k)): y.append(A*sin(k[i])) tck =interpolate.UnivariateSpline(x, y, w=None, bbox=[None, None], k=5, s=2) M=tck(k) </code></pre> <p>Below are the results for M for A = 1.e0 and A = 1.e-2</p> <p><a href="http://i.imgur.com/uEIxq.png" rel="nofollow">http://i.imgur.com/uEIxq.png</a> Amplitude = 1</p> <p><a href="http://i.imgur.com/zFfK0.png" rel="nofollow">http://i.imgur.com/zFfK0.png</a> Amplitude = 1/100</p> <p>Clearly the interpolated function created by the splines is totally incorrect! The 2nd graph does not even oscillate the correct frequency.</p> <p>Does anyone have any insight into this problem? Or know of another way to create splines within numpy/scipy? </p> <p>Cheers, Rory</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload