exo3.mw

> restart;

>

> Exercice 3

> question a)

> A:=array(1..3,1..4): for i from 1 to 3 do for j from 1 to 4 do A[i,j]:=i+j: od:od:

> A=evalm(A);

A = matrix([[2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7]])

> A1:=Dilat_ligne(1/2,1,A); L2 <-- L2/2

A1 := matrix([[1, 3/2, 2, 5/2], [3, 4, 5, 6], [4, 5, 6, 7]])

> A2:=Transvect_ligne(2,-3,1,A1); L2 <-- L2- 3*L1

A2 := matrix([[1, 3/2, 2, 5/2], [0, (-1)/2, -1, (-3)/2], [4, 5, 6, 7]])

A3:=Transvect_ligne(3,-4,1,A2);  L3 <-- L3- 4*L1

A3 := matrix([[1, 3/2, 2, 5/2], [0, (-1)/2, -1, (-3)/2], [0, -1, -2, -3]])

> question b)

> Gauss1:=proc(A)
local t,B,k;

t:=taille(A);  

B:=array(1..t[1],1..t[2]);

B:=evalm(A);
B
contient une copie exact de A, mais B est modifiable contrairement à A
B:=Dilat_ligne(1/B[1,1],1,B);         
L1 <--1/a(11) *L1
for k from 2 to t[1] do

 B:=Transvect_ligne(k,-B[k,1],1,B);  
Lk <-- Lk- a(k1)*L1

od;

evalm(B);

end:

> Gauss1(A); On retrouve comme prévu:

matrix([[1, 3/2, 2, 5/2], [0, (-1)/2, -1, (-3)/2], [0, -1, -2, -3]])

>

>

> question c)

> zero_sous_pivot:=proc(i,A)
local t,B,k;

t:=taille(A);  

B:=array(1..t[1],1..t[2]);

B:=evalm(A);
B
contient une copie exact de A, mais B est modifiable contrairement à A
la procédure ne marche que si l'indice i ne dépasse pas la taille de la matrice et le pivot
a(ii) est NON NUL
if is(i>t[2]) or is(i>t[1]) or is(B[i,i]=0) then RETURN(IMPOSSIBLE); fi;

B:=Dilat_ligne(1/B[i,i],i,B);         
Li <--1/a(ii) *Li

for k from i+1 to t[1] do   
k parcourt les indice de ligne en dessous du pivot
 B:=Transvect_ligne(k,-B[k,i],i,B);  
Lk <-- Lk- a(ki)*Li
od;

evalm(B);

end:

>

> question d)

> Gauss_systeme:=proc(A)
local T,i,j,t;

t:=taille(A);

T:=array(1..t[1],1..t[2]);

T:=evalm(A);
T contient une copie exact de A, mais T est modifiable contrairement à A
for j from 1 to min(t[1],t[2]) do
on parcourt les éléments de la diagonale d'indice jj
 i:=CherchePivot_colonne(T,j);
On cherche un  pivot non nul dans la colonne j
 if i<>0 then T:=Permut_ligne(i,j,T);   
Au cas où l'on trouve ce pivot, on permute avec la ligne actuel et  on annule les coefficients sous celui-ci
              T:=zero_sous_pivot(j,T);

 fi;
sinon on passe à la colonne suivante

od;

evalm(T);

end:

>

> question e)

> B:=array(1..4,1..5): for i from 1 to 4 do for j from 1 to 5 do B[i,j]:=i+j: od:od:

> B=evalm(B);

B = matrix([[2, 3, 4, 5, 6], [3, 4, 5, 6, 7], [4, 5, 6, 7, 8], [5, 6, 7, 8, 9]])

> Gauss_systeme(B);

matrix([[1, 3/2, 2, 5/2, 3], [0, 1, 2, 3, 4], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])

Ainsi, puisque les deux dernières équations sont compatibles,  il ne nous reste plus qu'à étudier le système

> x+3*y/2+2*z+5*t/2=3; y+2*z+3*t=4;

x+3/2*y+2*z+5/2*t = 3

y+2*z+3*t = 4

où les inconnues z et t jouent le rôle de paramètres