Demo entry 6763441

toto

   

Submitted by anonymous on Oct 22, 2018 at 17:13
Language: Python 3. Code size: 615 Bytes.

import math
import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import interp1d

ord=9

a=1/8
def f(x):
    return np.exp(-a*x**2)

x = np.linspace(-10, 10, num=11, endpoint=True)
y = f(x)

interpf  = interp1d(x, y, kind='cubic')
interpfn = interp1d(x, y, kind=ord)
xnew = np.linspace(-10, 10, num=41, endpoint=True)
ynew=interpfn(xnew)

plt.plot(x, y, 'o', xnew, interpf(xnew), 'b-', xnew, interpfn(xnew), '--')

x = np.linspace(-10, 10, num=101, endpoint=True)
y = f(x)
plt.plot(x, y, 'r-')
plt.legend(['data', 'cubic', 'ord'+str(ord), 'ana'], loc='best')
plt.grid()

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).