# -*- coding: utf-8 -*- """ Created on Thu Dec 11 15:58:17 2014 @author: grivet listing 4.1 : Construction du polyôme d'interpolation de Lagrange Le module 'scipy.interpolate' comporte un programme 'lagrange' qui forme le polynôme d'interpolation """ import numpy as np import matplotlib.pyplot as plt npiv = 4 npt = 200 xpiv = np.array([0.5,-0.5,1.5,2.0]) fpiv = np.exp(xpiv) Lagrange = np.zeros(npt) L = np.zeros([npiv,npt],float) x = np.linspace(-2,3,npt) for i in range(npiv): L[i,:] = np.ones(npt) for k in range(npiv): if k != i: L[i,:] = L[i,:]*(x-xpiv[k])/(xpiv[i]-xpiv[k]) L[i,:] *= fpiv[i] plt.plot(x,L[i,:]) Lagrange = Lagrange + L[i,:] plt.plot(xpiv,fpiv,'ok') plt.plot(x,np.exp(x),'--k') plt.plot(x,Lagrange,'-k') plt.ylim(-5.0,11.0) plt.title("polynômes élémentaires et polynôme d'interpolation") plt.xlabel("$x$")