ASI 3
Méthodes numériques pour l’ingénieur
Interpolation
f(x)
-4 -3 -2 -1 0 1 2
Approximation de fonctions
• Soit une fonction f (inconnue explicitement)
– connue seulement en certains points x0,x1…xn
– ou évaluable par un calcul coûteux.
• Principe :
– représenter f par une fonction simple, facile à évaluer
• Problème :
– il existe une infinité de solutions !
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 -4
-3 -2 -1 0 1 2
Approximation de fonctions
• Il faut se restreindre à une famille de fonctions
– polynômes, – exponentielles,
– fonctions trigonométriques…
Quelques méthodes d'approximation
• Interpolation polynomiale
– polynômes de degré au plus n
• polynômes de Lagrange
• différences finies de Newton
• Interpolation par splines
– polynômes par morceaux
• Interpolation d'Hermite
– informations sur les dérivées de la fonction à approcher
• ...voir le groupe de TT…
ab ab
f(x) P(x) f(x)+
f(x)- f(x) P(x) f(x)+
f(x)-
Théorème d’approximation de Weierstrass
a bx x
P x
f
b a x
P a b
f
,
) ( )
(
: que tel
, sur définit ,
) ( polynôme un
existe il
, 0
Alors,une fonction définie et continuesur l'intervalle , soit
) (x f
) (x P
) (x f
) (x f
grand est
polynome du
ordre l'
plus , est petit, plus
Interpolation :
Interpolation polynomiale
• Le problème : les données, la solution recherchée
• mauvaise solution : résoudre le système linéaire
• la combinaison linéaire de polynômes est un polynôme
n i
x f x
P x
P
x f y
x x
f y
x x
f y
x
i i
i i
i i
i i
, 0 ),
( )
( que tel
) (
) ( ,
,..., )
( ,
,..., )
(
, 0 0
0
0
1
0
) (
) ( ...
) ( )
( ainsi
0
) ( et 1 )
( que tel
) (
) ( ...
) ( )
(
0 0 0
0
i n n i
i i i
i
j i i
i
n n i
i
x P y x
P y x
P y x
P
i j x
P x
P
x P y x
P y x
P y x
P
e Vandermond de
matrice :
)
(
0
V y
Va x
a x
P n
i
i i
Interpolation polynomiale : Lagrange
• Théorème
– Soient n+1 points distincts xi réels et n+1 réels yi, il existe un unique polynôme p Pn tel que
p(xi) = yi pour i = 0 à n – Construction de p :
avec Li polynôme de Lagrange – Propriétés de Li
• Li(xi)=1
• Li(xj)=0 (j i)
n
0 i
i
iL ( x ) y
) x ( p
n
i j 0
j i j
j
i x x
x ) x
x ( L
L est un polynôme d’ordre n démonstration
0 1
0 1
1 0
1 0
1 0
0 1
1 0
1 0
1 0
0 1 1
0 1
0
1 0
x x
x y x
x x
x y x
x x
x y x
x x
x y x
y
x x
y x y
x x x x
y y y
• Exemple avec n=1
– on connaît 2 points (x0,y0) et (x1,y1)
– on cherche la droite y=ax+b (polynôme de degré 1) qui passe par les 2 points :
• y0 = a x0 + b a = (y0 - y1) / (x0 - x1)
• y1 = a x1 + b b = (x0 y1 - x1 y0) / (x0 - x1)
–
Lagrange : exemple n°1
L0(x) L1(x)
x0 x1 y1
y0
Lagrange : exemple n°2
• Exemple avec n=2
– on connaît 3 points (0,1), (2,5) et (4,17) – polynômes de Lagrange associés :
8
4 x
2 ) x
x (
L0
8 2 x
) x x (
L2
44 x
) x x ( L1
0 2 4
-
0 2 4 0 2 4
-1 0 1 2 3 4 5 0
5 10 15 20 25 30
Lagrange : exemple n°2
– calcul du polynôme d'interpolation
• p(x)=L0(x) + 5 L1(x) + 17 L2(x)
• en simplifiant, on trouve p(x)=x2+1
Lagrange : l’algorithme
Complexité du calcul : n2 fait fait * ( ) ( )
)
* (
; ,
à jusqu' 1
pour
1 jusqu'à pour
l y y
y
j x i
x
j x l x
l
i j n
j n
i
i
i i
i
Fonction y = lagrange(x,xi,yi)
-1 0 1 2 3 4 5 -10
0 10 20 30 40 50 60
Lagrange : exemple n°3
• Exemple avec n=2 (fonction à approcher y=ex) – on connaît 3 points (0,1), (2,7.3891) et (4,54.5982)
– Polynôme d'interpolation
• p(x) =L0(x) + 7.3891 L1(x) + 54.5982 L2(x)
Lagrange : exemple n°3
– Erreur d'interpolation e(x) = f(x) - p(x)
-1 0 1 2 3 4 5
-20 -10 0 10 20 30 40 50 60
Lagrange : erreur d'interpolation
• Théorème :
– si f est n+1 dérivable sur [a,b], x [a,b], notons :
• I le plus petit intervalle fermé contenant x et les xi
(x)=(x-x0)(x-x1)…(x-xn)
– alors, il existe I tel que – NB : dépend de x
• Utilité = on contrôle l’erreur d’approximation donc . la qualité de l’approximation
n 1
! xx f e
) 1 n
(
Lagrange : choix de n
• Supposons que l'on possède un nb élevé de points pour approcher f … faut-il tous les utiliser ?
– (calculs lourds)
• Méthode de Neville :
– on augmente progressivement n
– on calcule des Li de manière récursive
– on arrête dès que l'erreur est inférieure à un seuil
(d’ou l’utilité du calcul de l’erreur)
La méthode de Neuville
• Définition
• Théorème
• Démonstration
• Application systématique
k k
k
m m
m m
m m
m m
m
y x
y x
y x
k
x P
, ,...,
, ,
,
points les
sur calculé
Lagrange de
polynôme
) (
2 2
1 1
2 1, ,...,
j i
n i
i i
n j
j j
x x
x P
x x x
P x x x
P
( ) ( )
)
( 0,1,..., 1, 1,..., 0,1,..., 1, 1,...,
) ( )
( et
) ( )
( );
( )
(xi f xi P xj f xj P xk f xk
P
2 , 2 2
, 1 , 0 1
, 2 2
, 1 0
, 2 2
2
1 , 1 1
, 0 0
, 1 1
1
0 , 0 0
0
Q P
Q P
Q P
Q P
x
Q P
Q P
Q P
x
Q P
Q P
x
Q P
x
i j i j i j i i
P
Q , , 1,..., 1,
L’algorithme de Neuville
Complexité du calcul : n2
fait fait ( , ) ( ) ( )
1 1
) ( 1
) (
à jusqu' 1
pour
1 jusqu'à pour
fait ( ,10)jusqu'à( ) pour
n n Q y
j i x i
x
) ,j
Q(i i
x x )
Q(i,j j
i x Q(i,j) x
i
j n
i
i y i
Qi n
i i
i i
i
Fonction y = Neuville(x,xi,yi)
Interpolation polynomiale : Newton
• Polynômes de Newton :
– base = {1, (x-x0), (x-x0)(x-x1), …, (x-x0)(x-x1)…(x-xn-1)}
– on peut ré-écrire p(x) :
p(x)=a0 + a1(x-x0) + a2(x-x0)(x-x1)+…+ an(x-x0)(x-x1)…(x-xn-1) – calcul des ak : méthode des différences divisées
Newton : différences divisées
• Définition :
– Soit une fonction f dont on connaît les valeurs en des points distincts a, b, c, …
– On appelle différence divisée d’ordre 0, 1, 2,...,n les expressions définies par récurrence sur l’ordre k : – k=0 f [a] = f (a)
– k=1 f [a,b] = ( f [b] - f [a] ) / ( b - a )
– k=2 f [a,b,c] = ( f [a,c] - f [a,b] ) / ( c - b ) – … f [X,a,b] = ( f [X,b] - f [X,a] ) / ( b - a )
a X , b X , a b
Newton : différences divisées
• Théorèmes :
– détermination des coefficients de p(x) dans la base de Newton :
f [x0, x1,…, xk] = ak avec k = 0 … n – erreur d'interpolation :
e(x) = f [x0, x1,…, xn, x] (x)
Newton : différences divisées
a0
a1
a2
an
• Calcul pratique des coefficients :
x0 f [x0]
x1 f [x1] f [x0, x1]
x2 f [x2] f [x1, x2] f [x0, x1, x2]
… … … ...
… … … f [xn-3, xn-2, xn-1]
xn f [xn] f [xn-1, xn] f [xn-2, xn-1, xn] … f [x0, ..., xn]
Newton : exemple
a0
a2
p(x)=1 + 2x + x(x-2) (et on retombe sur p(x) = 1 + x2)
a1
• (ex. n°2) : n=2 (0,1), (2,5) et (4,17)
0 f [x0]=1
2 f [x1]=5 f [x0, x1]
=(1-5)/(0-2)=2
4 f [x2]=17 f [x1, x2] f [x0, x1, x2]
=(5-17)/(2-4)=6 = (2-6)/(0-4)=1
Newton : l’algorithme
Complexité du calcul : n2 fait (i) 1 jusqu'( ,à)
pour
fait fait ( ) ( ) 1 1
1
à jusqu' 1
pour
1 jusqu'à pour
fait ( ,10)jusqu'à( ) pour
i n F
ai n
j i x i
x
) ,j
F(i )
F(i,j F(i,j)
i
j n
i
i y i
Fi n
i i
i
Fonction a = Newton(xi,yi)
-6 -4 -2 0 2 4 6
A bas les polynômes
• Ex : y=2(1+tanh(x)) - x/10 avec 9 points
– entre les points, le polynôme fait ce qu'il veut…
et plus son degré est élevé plus il est apte à osciller !
Interpolation par splines cubiques
• Principe :
– on approche la courbe par morceaux (localement)
– on prend des polynômes de degré faible (3) pour éviter les oscillations
Splines cubiques : définition
• Définition :
– On appelle spline cubique d’interpolation une fonction notée g, qui vérifie les propriétés suivantes :
• g C2[a;b] (g est deux fois continûment dérivable),
• g coïncide sur chaque intervalle [xi; xi+1] avec un polynôme de degré inférieur ou égal à 3,
• g(xi) = yi pour i = 0 … n
• Remarque :
– Il faut des conditions supplémentaires pour définir la spline d’interpolation de façon unique
– Ex. de conditions supplémentaires :
• g"(a) = g"(b) = 0 spline naturelle.
Splines : illustration
P1(x)=1x3+1x2+1x+1
=a1 (x-x1)3+b1 (x-x1)2+c1 (x-x1)+d1
P2(x)=a2 (x-x2) 3+b2 (x-x2)2+c2 (x-x2)+d2
Splines cubiques : détermination
• Détermination de la spline d’interpolation
– g coïncide sur chaque intervalle [xi; xi+1] avec un polynôme de degré inférieur ou égal à 3
g" est de degré 1 et est déterminé par 2 valeurs:
• mi = g"(xi) et mi+1 = g"(xi+1) (moment au noeud n°i)
– Notations :
• hi = xi+1 - xi pour i = 0 … n-1
i= [xi; xi+1]
• gi(x) le polynôme de degré 3 qui coïncide avec g sur l’intervalle i
Splines cubiques : détermination
– g"i(x) est linéaire :
x i
• on intègre (ai constante)
• on continue (bi constante)
– gi(xi) = yi – gi(xi+1) = yi+1
i 1 i i
i 1 i i
i h
x m x
h x m x
x
g
i
i
ii 1 3 i i
i i 3 1
i
i a x x b
h 6
x m x
h 6
x m x
x
g
i i
1 2 i i
i i 2 1
i
i a
h 2
x m x
h 2
x m x
x
g
i i2
i i b
6 h
y m
i i
i i2
1 1 i
i a h b
6 h
y m
1
2
Splines cubiques : détermination
– g'(x) est continue : – et
– on remplace les ai dans :
– Rappel : on cherche les mi (n+1 inconnues)
on a seulement n-1 équations grâce à
il faut rajouter 2 conditions, par exemple
m0 = mn =0 (spline naturelle)
i i i i i i 1 i 1 i 1
ii a g x
2 m h 2 a
m h x
g
i 1 i
i
i 1 i
i
i m m
6 y h
h y
a 1
3
1 2
3
i i 1
1 i i
1 i i 1
i i i
1 i i
1 i 1
i y y
h y 1
h y 6 1 m
h m
h h
2 m
4 h
4
Splines cubiques : détermination
– Ex de résolution avec hi = xi+1 - xi constant :
•
• forme matricielle : Tm=f
• T inversible (diagonale strictement dominante)
i i 1
1 i i
1 i i 1
i i i
1 i i
1 i 1
i y y
h y 1
h y 6 1 m
h m
h h
2 m
4 h
i 1 i i 1
i1 2 i i
1
i y 2y y f
h m 1
m 4
m
n 1
1
1 n
1
f f
m m
4 1
1 4
1 1 4
1
0 1
4
Splines cubiques : l’algorithme
Complexité du calcul : complexité du solveur
fait ( ) ( ) 6
6 ) 1
(
1
; 1
pour [0,\2 ,01]2 1 fait
6 )
1 (
2 )
1 ,
(
( , 1) ( , ) 2 2; 1 pour
1 1
1 1 1
1 1
i i
i i i
i i
i
i i i
i i i
i i
i i
h i m
y i
b
m h m
y h y
i a
n i m
m T f
m T :n- , :n- T
h y y
h y i y
f
h i
i
T i i h
T i i h h
Ti n
Splines cubiques : exemple
• Ex : y=2(1+tanh(x)) - x/10 avec 9 points
-6 -4 -2 0 2 4 6
-6 -4 -2 0 2 4 6
spline
polynôme de degré 8
Conclusion
• Interpolation polynomiale
– évaluer la fonction en un point : Polynôme de Lagrange ->
méthode de Neville
– compiler la fonction : Polynôme de Newton
• Interpolation polynomiale par morceau : splines
– spline cubique d’interpolation
– spline cubique d’approximation (on régularise) – b spline
– spline généralisée : splines gausiènnes (multidimensionelle)