Ce programme permet la résolution numérique d'un système d'équations linéaires.
Les systèmes sont édités puis sauvegardés (format .txt) dans le repertoire "matrices".
Le programme montre la résolution étape par étape du système.
Le rang du système est donné à la dernière étape.
Source / Exemple :
procedure TForm1.resolClick(Sender: TObject);
var
i,j : integer;
a,coef : extended;
b,pivot_af : string;
begin
// à l'initialisation toutes les étapes sont true sauf etape1 à false.
// étape 5
if etape5=false then etape1:=false;
etape5:=true;
// étape 4,élimination des coef. de la colonne pivot : Li=Li-aij*Lipiv.
if etape4=false then
begin
edit1.text:='élimination des coef. de la colonne pivot(rang='+inttostr(rang)+')';
sleep(2000);
for i:=1 to dim.ligne do
begin
if i<>ipiv then
begin
coef:= mat[i,jpiv];
for j:=1 to dim.colonne do
begin
mat[i,j]:= mat[i,j]-coef*mat[ipiv,j];
end;
vect[i]:=vect[i]-vect[ipiv]*coef;
end;
end;
form1.paint;
if rang=dim.ligne then
begin
etape4:=true;
end
else
begin
etape4:=true;etape5:=false;
pivot:=false;
end;
end;
// étape 3, division de la ligne par le pivot.
if etape3=false then
begin
a:=mat[ipiv,jpiv];
str( a:3:3,pivot_af);
edit1.text:='division de la ligne '+inttostr(ipiv)+' par le pivot.('+pivot_af+')';
sleep(1000);
for j:=1 to dim.colonne do
begin
mat[ipiv,j]:=mat[ipiv,j]/a;
end;
vect[ipiv]:=vect[ipiv]/a;
form1.paint;
etape3:=true;etape4:=false;
end;
// étape 2, permutation des lignes ou colonnes.
if etape2=false then
begin
edit1.text:='ipiv ='+inttostr(ipiv);
if ipiv<>rang then
begin
edit1.text:='permutation des lignes '+inttostr(rang)+' et '+inttostr(ipiv);
sleep(1000);
for j:=1 to dim.colonne do
begin
a:= mat[rang,j];
mat[rang,j]:= mat[ipiv,j];
mat[ipiv,j]:= a;
end;
a:=vect[rang];
vect[rang]:=vect[ipiv];
vect[ipiv]:=a;
end;
if jpiv<>rang then
begin
edit1.text:='permutation des colonnes'+inttostr(rang)+'et'+inttostr(jpiv);
sleep(2000);
for i:=1 to dim.ligne do
begin
a:= mat[i,rang];
mat[i,rang]:= mat[i,jpiv];
mat[i,jpiv]:= a;
end;
b:=inc[rang];
inc[rang]:=inc[jpiv];
inc[jpiv]:=b;
end;
form1.Paint;
ipiv:=rang;
jpiv:=rang;
etape2:=true;etape3:=false;
end;
// étape 1, recherche du pivot dans une sous-matrice complète.
if etape1=false then
begin
for j:=rang+1 to dim.colonne do
begin
for i:= rang+1 to dim.ligne do
begin
if pivot = false then
begin
if mat[i,j] <> 0 then
begin
pivot:= true;
rang:=rang+1;
ipiv:=i;
jpiv:=j;
end;
end;
end;
end;
if pivot=true then
begin
str(mat[ipiv,jpiv]:3:3,pivot_af);
edit1.text:=' pivot trouvé '+inttostr(ipiv)+','+inttostr(jpiv)+' = '+pivot_af;
sleep(1000);
end;
if (pivot = false) and (rang = 0) then edit1.text:='rang nul';
if (pivot = false) and (rang <> 0) then edit1.text:='rang de ce syst. linéaire = '+inttostr(rang);
if pivot = true then
begin
if (ipiv<> rang) or (jpiv<> rang) then
begin
edit1.text:='permutation '+inttostr(ipiv)+inttostr(jpiv);
etape1:=true;etape2:=false;
end
else
begin
// edit1.text:='division de la ligne '+inttostr(ipiv)+'par le pivot';
etape1:=true;etape3:=false;
end;
end;
end;
end;
Conclusion :
Une évolution du programme serait de faire un calcul formel sur des équations contenant des paramètres...
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.