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: Exercice 5question a)zero_sur_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 \340 A
la proc\351dure ne marche que si l'indice i ne d\351passe pas la taille de la matrice et le pivot a(ii) est DIFFERENT DE 1
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 k parcourt les indice de ligne au dessus du pivot
B:=Transvect_ligne(k,-B[k,i],i,B); Lk <-- Lk- a(ki)*Li
od;
evalm(B);
end:
question b)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); T contient une copie exact de A, mais T est modifiable contrairement \340 A
if (t[1]<>t[2]-1) then RETURN(IMPOSSIBLE) fi; Cette proc\351dure ne fonctionne pas si le systeme n'a pas autant de lignes que d'inconnues
for j from 1 to t[1] do On annule les coefficients sous la diagonale et on transforme les coefficients diagonaux en 1
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; Cette proc\351dure ne fonctionne pas si le systeme n'est pas de CRAMER
sol:=NULL;
for j from t[1] to 1 by -1 do On annule les coefficients au dessus de la diagonale en commencant par la derni\350re colonne de la matrice associ\351e au syst\350me
T:=zero_sur_pivot(j,T);
sol:=T[j,t[2]],sol; sol contient la s\351quence des coefficients de la derni\350re colonne de B en commencant par le dernier coefficient yn du second membre
od;
[sol];
end:question c)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);B:=array(1..4,1..5): for i from 1 to 4 do for j from 1 to 5 do B[i,j]:=min(i,j): od:od:B[1,5]:=y1:B[2,5]:=y2:B[3,5]:=y3:B[4,5]:=y4:B=evalm(B);Gauss_systeme_cramer(B);