restart;
taille:=proc(A)
local t,u,n,p;
t:=[op(2,evalm(A))];
n:=op(2,t[1]);p:=op(2,t[2]);
[n,p];
end:Permut_ligne:=proc(i,j,A)
local B,k,t;
t:=taille(A);
B:=array(1..t[1],1..t[2]);
B:=evalm(A);
for k from 1 to t[2] do
B[i,k]:=A[j,k]; B[j,k]:=A[i,k];
od;
evalm(B);
end: Dilat_ligne:=proc(a,i,A)
local k,t,B;
t:=taille(A);
B:=array(1..t[1],1..t[2]);
B:=evalm(A);
for k from 1 to t[2] do
B[i,k]:=a*A[i,k];
od;
evalm(B);
end:Transvect_ligne:=proc(i,a,j,A)
local k,t,B;
t:=taille(A);
B:=array(1..t[1],1..t[2]);
B:=evalm(A);
for k from 1 to t[2] do
B[i,k]:=A[i,k]+a*A[j,k];
od;
evalm(B);
end:CherchePivot_colonne:=proc(A,i)
local t,k;
t:=taille(A);
if is(i>t[1])then RETURN(IMPOSSIBLE); fi;
for k from i to t[1] do
if is(A[k,i]<>0) then RETURN(k); fi;
od;
RETURN(0);
end:Permut_colonne:=proc(i,j,A)
local B,k,t;
t:=taille(A);
B:=array(1..t[1],1..t[2]);
B:=evalm(A);
for k from 1 to t[1] do
B[k,i]:=A[k,j]; B[k,j]:=A[k,i];
od;
evalm(B);
end: zero_sous_pivot:=proc(i,A)
local t,B,k;
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;
B:=Dilat_ligne(1/B[i,i],i,B);
for k from i+1 to t[1] do
B:=Transvect_ligne(k,-B[k,i],i,B);
od;
evalm(B);
end: zero_sur_pivot:=proc(i,A)
local t,B,k;
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
B:=Transvect_ligne(k,-B[k,i],i,B);
od;
evalm(B);
end:
Gauss_systeme_cramer:=proc(A)
local T,i,j,t,sol;
t:=taille(A);
T:=array(1..t[1],1..t[2]);
T:=evalm(A);
if (t[1]<>t[2]-1) 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);
T:=zero_sous_pivot(j,T);
fi;
od;
if (sum(T[k,k],k=1..t[1])<>t[1]) then RETURN(IMPOSSIBLE) fi;
sol:=NULL;
for j from t[1] to 1 by -1 do
T:=zero_sur_pivot(j,T);
sol:=T[j,t[2]],sol;
od;
[sol];
end:Exercice 6question 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\351quence des op\351rations \351l\351mentaires effectu\351es 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\351quence des op\351rations \351l\351mentaires effectu\351es 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\351quence des op\351rations \351l\351mentaires effectu\351es 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\351
hist:=Gauss_systeme_cramer_historique(A);
m:=nops(hist);
On applique les m\352mes op\351rations sur les lignes \340 l'identit\351 In que celles appliqu\351e \340 A pour passer de A \340 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);Gauss_inverse(A);