Python
import numpy as np import matplotlib.pyplot as plt from math import cos, pi def ddNewton( X, Y ) : def interpol( x, X, Y, coeffs ) : def compareTrace( f, subdiv, xmin, xmax, ymin, ymax ) : X = np.linspace( xmin, xmax, 500 ) Y = f(X) fY = f(subdiv) coeffs = ddNewton(subdiv, fY) YY = ( lambda x: interpol( x, subdiv, fY, coeffs ) )(X) plt.plot(X, YY, label = 'Interpolation') plt.plot(X, Y , label = 'Fonction originale') plt.axis( [xmin*1.2, xmax*1.2, ymin, ymax] ) plt.legend() plt.title('Interpolation et différences divisées') plt.show() def tcheb(n): def sub_reg( n, xmin, xmax ): def f(x): return 1.0 / ( 1.0 + 10.0*x*x ) # compareTrace( f, sub_reg( 20, -1, 1 ), -1, 1, -0.2, 1.2 ) # compareTrace( f, tcheb(20), -1, 1, -0.2, 1.2 )