1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| A:tableau(20,20)reel, i,j,k,n:entier; s :reel;
b,x: tableau(20)reel; rik : reel;
AA,BB,amax:reel;i0:entier; (* Gauss Pivot Partiel*)
j0:entier;Inc:tableau(20)reel; (*Gauss P.T*)
Début
(*Lecture des données *)
lire(n); lire(b(i),i=1,n); lire((a(i,j),j=1,n)i=1,n);
(*Initialisation de Inc à 1, 2 , 3, ....., n *)
pour i =1 à n faire inc(i) := i
fait;
Pour k =1 à n-1
faire (*recherche du pivot *)
amax := a(k,k); i0 := k;j0:=k;
pour i=k à n faire
pour j =k à n faire si abs(a(i,j))>abs(amax)
alors amax := a(i,j); j0:=j;i0:=i
fsi
fait;
fait;
(*permutation des lignes i0 et k dans A et B *)
pour j =K à n
faire aa := a(i0,j); a(i0,j) := a(k,j);
a(k,j) := aa
fait;
bb := b(i0);
b(i0) := b(k);
b(k) := bb;
(*permutation des colonnes j0 et k dans A et inc*)
pour i =k à n faire aa := a(i,j0); a(i,j0):=a(i,k);
a(i,k):=aa
fait;
bb:=inc(j0); inc(j0):= inc(k); inc(k) := bb
(* triangularisation de Gauss*)
pour i =k+1 à n faire rik := A(i,k)/A(k,k);
b(i) := b(i)-rik*b(k);
pour j = k+1 à n
faire A(i,j):= A(i,j)-rik*A(k,j) fait
fait
fait;
(* La remontée *)
x(inc(n))=b(n)/A(n,n);
pour i =n-1 à 1 pas -1
faire s:=0; pour j =i+1 à n
faire s := s+A(i,j)*x(inc(j)) fait;
x(inc(i)):= (b(i)-s)/A(i,i)
fait;
(* Impression des résultats *)
pour i = 1 à n
faire écrire(i,x(i)) fait
FIN |
Partager