# -*- coding: utf-8 -*- """ Created on Wed Jun 21 15:49:48 2017 Exercice 2-2 : Calcul du polynômes de Hermite par la relation de récurrence H_{n+1} = 2xH_n - 2nH_{n-1} @author: grivet """ import numpy as np import matplotlib.pyplot as plt def H(n,x): if n == 0: fn = 1 if n == 1: fn = 2*x if n > 1: k = 1; Havder = 1; Hder = 2*x while k < n: H = 2*x*Hder - 2*k*Havder Havder = Hder Hder = H k = k+1 fn = H; return fn xmin = -2.0; xmax = 2.0 x = np.linspace(xmin,xmax,200) fig = plt.figure() ax = fig.add_subplot(111) ax.plot(x,H(2,x),label = "n = 2") ax.plot(x,H(3,x),label = "n = 3") ax.plot(x,H(4,x),label = "n = 4") ax.plot(x,H(5,x),label = "n = 5") ax.spines['top'].set_color('none') ax.spines['left'].set_position('center') ax.spines['right'].set_color('none') ax.spines['bottom'].set_position('center') ax.spines['left'].set_smart_bounds(True) ax.spines['bottom'].set_smart_bounds(True) plt.legend() plt.xlabel("$x$"); plt.ylabel("$H_n(x)$"); plt.title("polynômes de Hermite, n = 2,3,4,5 ")