Есть прога, нужно в ней разобраться. Помогите кто чем может. если можно то побольше комментариев. ЗАРАНЕЕ БЛАГОДАРЕН.
Вот код
| Код | unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids;
type TForm1 = class(TForm) StringGrid1: TStringGrid; StringGrid2: TStringGrid; Memo1: TMemo; Button1: TButton; Button2: TButton; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; GroupBox1: TGroupBox; GroupBox2: TGroupBox; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form1: TForm1;
implementation
{$R *.dfm}
const s=4;
type matrix = array [1..s,1..s] of real;
function DetM(const M : matrix; n : word): real;
var
Z,P,D : array [0..s+1] of integer;
Pj,Dj,ZPj,i,j,k,ch : integer;
t,det : real;
begin
Det:=0; ch:=1;
for i:=1 to n do
begin Z[i]:=i; P[i]:=i; D[i]:=-1 end;
D[1]:=0; j:=n+1; Z[0]:=j; z[n+1]:=j;
while j <> 1 do
begin
t:=1;
for i:=1 to n do t:=t*M[i,Z[i]];
Det:=Det+ch*t;
ch:=(-1)*ch;
j:=n;
while Z[P[j]+D[j]]>j do
begin D[j]:=-D[j]; j:=j-1 end;
Pj:=P[j]; Dj:=Pj+D[j];
k:=Z[Pj]; Z[Pj]:=Z[Dj]; Z[Dj]:=k;
ZPj:=Z[Pj]; k:=P[ZPj]; P[ZPj]:=Pj; P[j]:=k;
end;
Result:=det;
end;
procedure TForm1.Button1Click(Sender: TObject);
const nn=10;
var a:array [1..nn,1..nn] of double;
x,b:array [1..nn] of double;
n,i,j,k:integer;d:double;
begin
n:=4;
Memo1.Clear;
for i:=1 to n do for j:=1 to n do a[i,j]:=StrToFloat(StringGrid1.Cells[j-1,i-1]);
for i:=1 to n do b[i]:=StrToFloat(StringGrid2.Cells[0,i-1]);
//Memo1.Lines.Add('................П Р Я М О Й Х О Д..............');
for i:=1 to n-1 do
begin
for k:=i+1 to n do
begin
d:=a[k,i]/a[i,i];
for j:=i+1 to n do
a[k,j]:=a[k,j]-a[i,j]*d;
b[k]:=b[k]-b[i]*d;
end;
end;
//Memo1.Lines.Add('................О Б Р А Т Ы Й Х О Д...........');
for i:=n downto 1 do
begin
for j:=i+1 to n do
b[i]:=b[i]-a[i,j]*x[j];
x[i]:=b[i]/a[i,i];
end;
Memo1.Lines.Add(' О Т В Е Т: ');
for i:=1 to n do Memo1.Lines.Add('X['+IntToStr(i)+']='+FloatToStr(x[i]));
end;
procedure TForm1.Button2Click(Sender: TObject); var a,d_: matrix;
d1,d,x: array[1..s] of real;
dx: array [1..s] of matrix;
k,i,j: integer; det_: real;
begin
Memo1.Clear;
for i:=1 to s do for j:=1 to s do
a[i,j]:=StrToFloat(StringGrid1.Cells[j-1,i-1]);
for i:=1 to s do
d[i]:=StrToFloat(StringGrid2.Cells[0,i-1]);
det_:=DetM(a,s);
for k:=1 to s do
begin
for i:=1 to s do for j:=1 to s do
if j<>k then dx[k,i,j]:=a[i,j] else dx[k,i,j]:=d[i];
d_:=dx[k];
d1[k]:=DetM(d_,s);
x[k]:=d1[k]/det_;
end; Memo1.Lines.Add(' О Т В Е Т: '); for i:=1 to s do Memo1.Lines.Add('x['+IntToStr(i)+']='+FloatToStr(x[i]));
end;
end.
|
|