Здравствуйте, JonMoxley!
Рисуете форму:
Копируете код:
[code lang=pascal h=300]unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;
const
n=4;
type
TMas=array[0..n,0..n]of real;
TForm1 = class(TForm)
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
Label1: TLabel;
Label2: TLabel;
Memo1: TMemo;
Button1: TButton;
Label3: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private{ Private declarations }
a:TMas;
public{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure Gauss(var a:TMas;b:integer);
const
e=1E-30;
var
c:real;
i,j:integer;
begin
if b<n then
begin
if a[b,b]<e then
begin
i:=b+1;
while(i<n)and(abs(a[i,b])<e) do inc(i);
if i=n then ShowMessage('two and more')else
for j:=b to n do
begin
c:=a[b,j];
a[b,j]:=a[i,j];
a[i,j]:=c;
end;
end;
for i:=n downto b do a[b,i]:=a[b,i]/a[b,b];
for i:=b+1 to n-1 do
for j:=n downto b do
a[i,j]:=a[i,j]-a[i,b]*a[b,j];
if b<n then Gauss(a,b+1);
end
else
begin
repeat
dec(b);
i:=n-1;
c:=a[b,i+1];
while b<i do
begin
c:=c-a[b,i]*a[n,i];
dec(i);
end;
a[n,b]:=c;
until b=0;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i,j:integer;
begin
{}
for i:=0 to Form1.StringGrid1.ColCount do
for j:=0 to Form1.StringGrid1.RowCount-1 do
a[j,i]:=0;
Form1.Memo1.Clear;
Form1.Memo1.Lines.Add('Enter data and press "Gauss"');
end;
procedure TForm1.Button1Click(Sender: TObject);
var
b:boolean;
c:double;
i,j:integer;
begin
b:=true;
for i:=0 to Form1.StringGrid1.ColCount-1 do
for j:=0 to Form1.StringGrid1.RowCount-1 do
if TryStrToFloat(Form1.StringGrid1.Cells[i,j],c)then
a[j,i]:=c{StrToFloat(Form1.StringGrid1.Cells[i,j])}else
b:=false;
if b then
for i:=0 to Form1.StringGrid2.RowCount-1 do
if TryStrToFloat(Form1.StringGrid2.Cells[0,i],c)then
a[i,n]:=c{StrToFloat(Form1.StringGrid2.Cells[0,i])}else
b:=false;
if b then
begin
Gauss(a,0);
Form1.Memo1.Clear;
for i:=0 to n-1 do
Form1.Memo1.Lines.Add(FloatToStr(a[n,i]));
end
else
ShowMessage('please check parametrs')
end;
end.[/code]
Запускаете.
Удачи!
Об авторе:
Мне безразлично, что Вы думаете о обо мне, но я рад за Вас - Вы начали думать.