ULCO 2019 - 2020
M1 Reherche IMAO
TP 7 – Splines cubiques – Correction
Exercice 1. a.
Pour i = 1, 2, 3, on a qi (x) = ai,1 + ai,2 (x − xi ). De qi (xi ) = ai,1 = yi , on ontient a1,1 = 1, a2,1 = 3 et
a3,1 = 2. De qi (xi+1 ) = ai,1 + ai,2 (xi+1 − xi ) = yi+1 , on obtient
ai,1
ai,2 = yi+1 − = yi+1 − ai,1 = yi+1 − yi ,
xi+1 − xi
et donc a1,2 = 3 − 1 = 2, a2,2 = 2 − 3 = −1 et a3,2 = 3 − 2 = 1. Ainsi on obtient :
0
1 1 2
X= 3 −1
2 et
2 1
3
b. On obient
polynome(M,X,i,k):=block([j,q],
q:0,
for j:1 thru k+1 do(
q:q+M[i][j]*(x-X[i][1])**(j-1)
),
return(q)
)
c. On obtient
polynomes(M,X):=block([k,n,size],
size:matrix_size(M),
n:size[1]+1,
k:size[2]-1,
return(makelist(polynome(M,X,i,k),i,1,n-1))
)
d. On obtient les polynôme à partir de X et M grâce aux fonctions précédents. Pour i = 1, ..., n − 1
on a xi = X[i] et yi = qi (xi ). De plus xn = X[n] et yn = qn (xn+1 ).
e. On obtient
affiche spline(M,X):=block([a,b,n,P,Q],
Q:polynomes(M,X),
n:length(Q)+1,
a:X[1][1],
b:X[n][1],
P:makelist([X[i][1],subst(x=X[i][1],Q[i])],i,1,n-1),
P:append(P,[[X[n][1],subst(x=X[n][1],Q[n-1])]]),
C:makelist(explicit(Q[i],x,X[i][1],X[i+1][1]),i,1,n-1),
wxdraw2d(point type=circle,points(P),color=red,C,proportional axes = ’xy)
)
2
f. On obtient
g. Il y’a n − 1 polynômes qi de degré 2 et donc 3(n − 1) = 3n − 3 inconnues. On a n − 1 équations
de la forme qi (xi ) = yi , n − 1 équations de la forme qi (xi+1 ) = yi+1 et n − 2 équations de la forme
qi0 (xi + 1) = qi+1
0
(xi ). Au finale on a 2(n − 1) + (n − 2) = 3n − 4 équations. Il manque donc une condition.
h. On obtient
i. On obtient
j. On obtient
k. La valeur de la dérivée en x0 à un impact majeur sur l’allure globale de la courbe : ce n’est pas
raisonnable en pratique.
3
Exercice 2.
a. Il y’a n − 1 polynômes qi de degré 3 et donc 4(n − 1) = 4n − 4 inconnues. On a n − 1 équations
de la forme qi (xi ) = yi , n − 1 équations de la forme qi (xi+1 ) = yi+1 , n − 2 équations de la forme
qi0 (xi + 1) = qi+1
0
(xi ). Au finale on a 2(n − 1) + 2(n − 2) = 4n − 6 équations. Il manque donc deux
conditions.
b. On a qi0 (x) = 3ai (x − xi )2 + 2bi (x − xi ) + ci et qi00 (x) = 6ai (x − xi ) + 2bi .
L’équation (1) devient
di = yi (5)
L’éqution (2) devient
ai (xi+1 − xi )3 + bi (xi+1 − xi )2 + ci (xi+1 − xi ) + di = yi+1 . (6)
L’éqution (3) devient
3ai (xi+1 − xi )2 + 2bi (x − xi ) + ci = ci+1 (7)
L’équation (4) devient
3ai (xi+1 − xi ) + bi = bi+1 (8)
Exercice 3.
a. On a mi = qi00 (xi ) = 2bi et donc
mi
bi = (9)
2
mi+1
b. par l’équation (8) on a 3ai hi = bi+1 − bi = 2 − m2i et donc
mi+1 − mi
ai = . (10)
6hi
c. L’équation (6) devient ai h3i + bi h2i + ci hi = yi+1 − di = yi+1 − yi et donc après calcul
yi+1 − yi mi+1 − mi mi
ci = − hi − hi . (11)
hi 6 2
Exercice 4.
La seule équation pas encore untilisée est la (7). En remplaceant ai , bi , ci et di = yi par leurs expressions
en fonction de hi , mi et yi on obtient
yi+2 − yi+1 yi+1 − yi
hi mi + 2(hi + hi+1 )mi+1 + hi+1 mi+2 = 6 − (12)
hi+1 hi
Exercice 5. En ajoutant les conditions m1 = 0 et mn = 0 on est amené à résoudre le système AY = B
suivant :
0
1 m1
y3 −y2
h1 2(h1 + h2 ) h2 m2
h2 − y2h−y 1
1
y −y y −y
h2 2(h2 + h 3 ) h3
m3
4
h 3
3
− 3
h 2
2
× .. = 6
. . . . . .
..
. . . . .
−y −y
y y
hn−2 2(hn−2 + hn−1 ) hn−1 mn−1 hn−1 −
n n−1 n−1 n−2
hn−2
1 mn 0
| {z } | {z } | {z }
A Y B
b. On résoud construit puis résoud le système précédent. Pour l’affichage de la spline cubique, on
utilise les fonctions de l’exercice 1.
4
spline_cubique(P):=block([i,n,A,B,h,Y,m],
n:length(P),
h:makelist(P[i+1][1]-P[i][1],i,1,n-1),
A:zeromatrix(n,n),
B:zeromatrix(n,1),
for i:2 thru n-1 do (
B[i][1]:6*((P[i+1][2]-P[i][2])/h[i]-(P[i][2]-P[i-1][2])/h[i-1])
),
A[1,1]:1,
A[n,n]:1,
for i:2 thru n-1 do(
A[i,i-1]:h[i-1],
A[i,i]:2*(h[i-1]+h[i]),
A[i,i+1]:h[i]
),
Y:A^^(-1).B,
m:makelist(Y[i][1],i,1,n),
d:makelist(P[i][2],i,1,n-1),
b:makelist(m[i]/2,i,1,n-1),
a:makelist((m[i+1]-m[i])/(6*h[i]),i,1,n-1),
c:makelist((P[i+1][2]-P[i][2])/h[i]-h[i]*(m[i+1]-m[i])/6-h[i]*m[i]/2,i,1,n-1),
M:zeromatrix(n-1,4),
for i:1 thru n-1 do(
M[i,4]:a[i],
M[i,3]:b[i],
M[i,2]:c[i],
M[i,1]:d[i]
),
X:zeromatrix(n,1),
for i:1 thru n do(
X[i][1]:P[i][1]
),
affiche_spline(M,X)
)
c. Avec les point définis précédement, on obtient