Sei sulla pagina 1di 8

unit Unit1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls;

type

TForm1 = class(TForm)

Edit1: TEdit;

Edit2: TEdit;

Edit3: TEdit;

Edit4: TEdit;

Edit5: TEdit;

Edit6: TEdit;

Edit7: TEdit;

Edit8: TEdit;

Edit9: TEdit;

Edit10: TEdit;

Edit11: TEdit;

Edit12: TEdit;

Memo1: TMemo;

Button1: TButton;

Label1: TLabel;

Label2: TLabel;

Button2: TButton;
Memo2: TMemo;

Memo3: TMemo;

Memo4: TMemo;

U: TLabel;

Y: TLabel;

X: TLabel;

L: TLabel;

procedure Button2Click(Sender: TObject);

procedure Button1Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

const

n=3;

var

A:array[1..n,1..n] of double;

X:array[1..n] of double;

B:array[1..n] of double;

D:array[1..n] of double;

L:array[1..n,1..n] of double;

U:array[1..n,1..n] of double;

Y:array[1..n] of double;

som:double;

Form1: TForm1;
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

var

i,j,k:integer;

pivot,val: double;

begin

A[1][1]:= Strtofloat(Edit1.Text);

A[1][2]:= Strtofloat(Edit2.Text);

A[1][3]:= Strtofloat(Edit3.Text);

A[2][1]:= Strtofloat(Edit4.Text);

A[2][2]:= Strtofloat(Edit5.Text);

A[2][3]:= Strtofloat(Edit6.Text);

A[3][1]:= Strtofloat(Edit7.Text);

A[3][2]:= Strtofloat(Edit8.Text);

A[3][3]:= Strtofloat(Edit9.Text);

B[1]:= Strtofloat(Edit10.Text);

B[2]:= Strtofloat(Edit11.Text);

B[3]:= Strtofloat(Edit12.Text);

D[1]:= Strtofloat(Edit10.Text);

D[2]:= Strtofloat(Edit11.Text);

D[3]:= Strtofloat(Edit12.Text);

Memo1.Clear;

Memo2.Clear;
Memo3.Clear;

Memo4.Clear;

// Calcul de la matrice U

for j := 1 to n do

begin

for i := 1 to n do

begin

U[j][j]:=A[i][j] ;

for k := 1 to i-1 do

begin

U[i][j]:= U[i][j] - L[i][k]*U[k][j];

end;

end;

// Calcul de la matrice L

for i := j+1 to n do

begin

L[i][j]:=A[i][j] ;

for k := 1 to j-1 do

begin

L[i][j]:= L[i][j] - L[i][k]*U[k][j];

end;

L[i][j]:=L[i][j]/U[j][j] ;
for k := 1 to n do

begin

L[k][k]:= 1;

end;

end;

end;

// Affichage des matrices L et U respectivement sur les memos 1 et 2.

//Affichage de la matrice L sur le memo 1

for i := 1 to n do

begin

for j := 1 to n do

begin

Memo1.Lines.Add('L['+IntToStr(i)+']['+IntToStr(j)+']='+FloatToStr(L[i][j]));

end;

end;

// Affichage de la matrice U sur le memo 2

for i := 1 to n do

begin
for j := 1 to n do

begin

Memo2.Lines.Add('U['+IntToStr(i)+']['+IntToStr(j)+']='+FloatToStr(U[i][j]));

end;

end;

// Resolution de l'equation L*Y=B

if (L[1][1]<>0)then

begin

Memo3.Lines.Add('Les solutions de l''équation L*Y=B sont:');

Y[1]:=B[1]/L[1][1];

Memo3.Lines.Add('Y[1]='+FloatToStr(Y[1]));

for i:=2 to n do

begin

som:=0;

for j:=1 to i-1 do

begin

som:=som+L[i][j]*Y[j];

end;

Y[i]:=(1/L[i][i])*(B[i]-som);

Memo3.Lines.Add('Y['+intToStr(i)+']='+FloatToStr(Y[i]));

end;

end;
// Resolution de l'equation U*x=y

if (U[n][n]<>0)then

begin

Memo4.Lines.Add('Les solutions de l''équation U*X=Y sont:');

X[n]:=Y[n]/U[n][n];

Memo4.Lines.Add('X['+intToStr(n)+']='+FloatToStr(X[n]));

for i:= n-1 downto 1 do

begin

som:=0;

for j:=i+1 to n do

begin

som:= som + (U[i][j]*X[j]);

end;

X[i]:=(Y[i]-som)/U[i][i];

Memo4.Lines.Add('X['+IntToStr(i)+']='+FloatToStr(X[i]));

end;

end;

end;

procedure TForm1.Button2Click(Sender: TObject);

begin

Close;
end;

end.

Potrebbero piacerti anche