Simulation Numérique
Chapitre 2
Eléments d’Analyse Numérique
Eric Lunéville
Plan
Représentation des nombres
Techniques de stabilisation
Méthodologie
0.XXXXXXXX15 0.XXXXXXXX2
0.XXXXXXXX25 0.XXXXXXXX2
2 −M
Opérations : addition
Addition en double accumulateur
opération stable
Opérations : soustraction
Soustraction : même procédé, exemple (avec 4 chiffres) :
soustraction Alignement Addition Arrondi
x = .1000 10 0 x = .1000000 10 0 x−y = x⊖y =
y = .4000 10 −4 y = .0000400 100 .9999600 10 0 .1000 10 0
Erreur de cancellation
x = 0.1000 x + y = .10006 (x + y) − z = y
y = .00006 arrondi (x ⊕ y) ⊖ z = 0.0001
z=x x ⊕ y = .1001 erreur = 4 10 −5
Opérations : Stabilité
Processus numérique : Q : X ∈ R n −→ Q(X ) ∈ R p
Y − X
δB
≤ cond(A)
X
B
Instabilité numérique
Dérivation numérique : illustration numérique
const float e p s = 1 .E− 8 ;
f l o a t dh ( f l o a t h , f l o a t x )
{ f l o a t r =( e p s ∗ r a n d ( ) ) /RAND MAX ;
r e t u r n ( e p s+ s i n ( x+h)− s i n ( x ) ) / h ; } D é riva tion num é rique de s in( x) e n x=0
0
biais aléatoire
i n t m ain ( ) biais constant amplitude du biais : 10-8
{ o fstream out ( ” e r r ” ) ; -1
srand ( 1 ) ;
f l o a t x = 0; f l o a t h ; -2
c o n s t f l o a t l o g 1 0= l o g ( 1 0 ) ;
f o r ( i n t i = 1 ; i < 1 0 0 ; i ++) -3
log10(erreur)
{ h=e x p (− i ∗ l o g 1 0 / 2 0 ) ;
f l o a t d=dh ( h , x ) ;
-4
f l o a t e r r =a b s ( d − 1 . ) ;
o u t <<h<<” ”<< e r r <<e n d l ;
} -5
out . c l o s e ( ) ;
return 0 ; } -6
-7
-5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0
log10(h)
1
On suppose que f (x) ≈ 1 ⇒ I (f ) = 0 f (x)dx ≈ 1 et
f (x) − f (x) ≤ C 10 −q
I h (f ) − I (f ) ≤ I h (f ) − I h (f ) + |I h (f ) − I (f )|
nh
≤ C 10−q +C h
2
≤ C max(10−q , h 2 ) pas d’interférence des erreurs
Instabilité numérique
Intégration numérique, illustration numérique
flo a t r e c t a n g le b ( int n , f lo a t a , f lo a t b )
{ f l o a t h=(b−a ) / n ;
i n t k =0;
float r =0.;
w h i l e ( k<n ) Intégration numérique par la méthode des rectangles
0
{ f l o a t rp = 0.;
i n t k 2=m in ( n , k + 1 0 0 0 0 0 ) ;
f o r ( i n t i =k ; i <k 2 ; i ++) -1
r p+=f ( i ∗ h ) ;
k=k 2 ; -2
r+=r p ;
log10(erreur)
} -3
return r ∗h ; pente h
}
-4
erreurs d'arrondi
-6
-7
-7 -6 -5 -4 -3 -2 -1 0
log10(h)
sinh(x)
tanh(x) = NaN si x est grand !!!
cosh(x)
e x − e −x 1 − e −2x
= x = 1 si x est grand
e + e −x 1 + e −2x
u 1 = 1 − 1e
Exemple, calcul de la suite : u n+1 = n u n − 1
e
1
n→ ∞
propriétés : un = x n−1 e−x dx ⇒ 0 < u n < 1, u n ց, u n → 0
0
1
u
n+1 = n u
n −
calcul direct e ⇒u
n − u n = n!ε instable !
u
1 = u 1 + ε
v n + 1/e
calcul rétrograde v n−1 = avec v N = 0
n−1
vn + 1/e
vn−1 = (n − 1)!
n−1 ⇒ v n − vn = ε stable !
vN = ε (N − 1)!