Note that there are some explanatory texts on larger screens.

plurals
  1. POBehavior of scipy's splrep
    primarykey
    data
    text
    <p>I have a set of data points and would like to approximate them with a spline function. I used two different functions:</p> <ol> <li><em>splrep</em> from scipy</li> <li>and a cubic spline function that I found <a href="http://en.literateprograms.org/Cubic_spline_%28Python%29" rel="nofollow">here</a>.</li> </ol> <p>The results look like <a href="http://postimage.org/image/9wvq9gzdz/" rel="nofollow">this</a>.</p> <p>The code is as follows:</p> <pre><code>from matplotlib.pyplot import * from numpy import * from scipy import interpolate #---------------------------------------------- s = arange(257)/256.0 z = s[::-1] b = transpose(array((z*z*z, 3*z*z*s, 3*z*s*s, s*s*s))) def cubicspline(c,t): return dot(b[t],c) #---------------------------------------------- A = array([ [ -126.041 , 246.867004], [ -113.745003, 92.083 ], [ 208.518997, -183.796997], [ 278.859009, -190.552994]]) a1 = A[:,0] a2 = A[:,1] cs = reshape(A, (-1, 4, 2)) X = [] Y = [] #spline with cubicspline() for (x,y) in [cubicspline(c,16*t) for c in cs for t in arange(17)]: X.append(x) Y.append(y) # spline with splrep tck = interpolate.splrep( a1, a2) xnew = np.arange( min(a1), max(a1), 5) ynew = interpolate.splev(xnew, tck) plot(a1, a2, "--ob", ms = 9, label = "points") plot(X, Y, "r", lw=2, label = "cubicspline") plot(xnew, ynew, "g", lw=2, label = "splrep") legend(); savefig("image.png"); show() </code></pre> <p>As you may see the results of <em>splrep</em> are far from being satisfying. Can someone please explain this behavior and how to get reasonable approximation from <em>splrep</em>?</p>
    singulars
    1. This table or related slice is empty.
    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.
    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