exo6.mw

> restart;

>

> Exercice 6

> question b)

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

hist:=NULL;
t:=taille(A);  

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

B:=evalm(A);

if is(i>t[2]) or is(i>t[1]) or is(B[i,i]<>1) then RETURN(IMPOSSIBLE); fi;

 for k from 1 to i-1 do

 
hist:=hist,["Transvection_ligne",k,
-B[k,i],i]; hist contient la séquence des opérations élémentaires effectuées sur B
  B:=Transvect_ligne(k,-B[k,i],i,B);  

od;

evalm(B),
[hist];
end:

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

 
hist:=NULL;
t:=taille(A);  

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

B:=evalm(A);

if is(i>t[2]) or is(i>t[1]) or is(B[i,i]=0) then RETURN(IMPOSSIBLE); fi;

  
hist:=hist,["Dilate_ligne",1/B[i,i],i];

  B:=Dilat_ligne(1/B[i,i],i,B);   

for k from i+1 to t[1] do

 hist:=hist,["Transvection_ligne",k,-B[k,i],i];
hist contient la séquence des opérations élémentaires effectuées sur B
  B:=Transvect_ligne(k,-B[k,i],i,B);

od;

evalm(B),
[hist];

end:

> Gauss_systeme_cramer_historique:=proc(A)
local T,i,j,t,
hist,
temp;
hist:=NULL;
t:=taille(A);

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

T:=evalm(A);

if (t[1]<>t[2]) then RETURN(IMPOSSIBLE) fi;

for j from 1 to t[1] do

 i:=CherchePivot_colonne(T,j);

 if i<>0 then T:=Permut_ligne(i,j,T);

              
hist:=hist,["Echange_ligne",i,j];
hist contient la séquence des opérations élémentaires effectuées sur B
             
temp:=zero_sous_pivot_historique(j,T);  
              T:=temp[1];

              
hist:=hist,op(temp[2]);
                   
 fi;

od;

if (sum(T[k,k],k=1..t[1])<>t[1]) then RETURN(IMPOSSIBLE) fi;

for j from  t[1] to 1 by -1  do  

   
temp:=zero_sur_pivot_historique(j,T);  
   T:=temp[1];

   
hist:=hist,op(temp[2]);
   
  od;

[hist];

end:

>

> question c)

> Gauss_inverse:=proc(A)
local T,j,k,q,t,m,hist;

t:=taille(A);

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

 for j from 1 to t[1] do

  for k from 1 to t[1] do    T[j,k]:=0;   od;  
tous les coefficients de la ligne j sont nulls
  T[j,j]:=1;
sauf celui d'indice j
 od;

 
On a a obtenu jusqu'ici la matrice identité
hist:=Gauss_systeme_cramer_historique(A);

m:=nops(hist);

On applique les mêmes opérations sur les lignes à l'identité In que celles appliquée à A pour passer de A à In
for j from 1 to m do

 q:=hist[j];

 if q[1]="
Echange_ligne
" then T:=Permut_ligne(q[2],q[3],T);
  elif q[1]="
Dilate_ligne
" then T:=Dilat_ligne(q[2],q[3],T);
  elif q[1]="
Transvection_ligne
" then T:=Transvect_ligne(q[2],q[3],q[4],T);
 fi;

od;

 evalm(T);

end:

>

>

>

>

>

> question d)

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

> A=evalm(A);

A = matrix([[1, 1, 1, 1], [1, 2, 2, 2], [1, 2, 3, 3], [1, 2, 3, 4]])

> Gauss_inverse(A);

matrix([[2, -1, 0, 0], [-1, 2, -1, 0], [0, -1, 2, -1], [0, 0, -1, 1]])

>

>

>