type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Edit1: TEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
BitBtn4: TBitBtn;
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
StringGrid3: TStringGrid;
Label7: TLabel;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
n:integer;
a:array[1..100,1..100] of real;
b,x:array[1..100] of real;
implementation
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
var i,j,k:integer;
sigma:real;
begin
for i:=1 to n do
for j:=1 to n do
a[i,j]:=StrToFloat(StringGrid1.Cells[j,i]);
for i:=1 to n do
b[i]:=StrToFloat(StringGrid2.Cells[1,i]);
x[1]:=b[1]/a[1,1];
for k:=2 to n do
begin
sigma:=0;
for j:=1 to k-1 do
sigma:=sigma+a[k,j]*x[j];
x[k]:=(b[k]-sigma)/a[k,k];
end;
for i:=1 to n do
begin
StringGrid3.Cells[i,0]:=IntToStr(i);
StringGrid3.Cells[i,1]:=FloatToStr(x[i]);
end;
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
var i:integer;
begin
StringGrid1.Visible:=true;
StringGrid2.Visible:=true;
n:=StrToInt(edit1.Text);
StringGrid1.ColCount:=n+1;
StringGrid1.RowCount:=n+1;
StringGrid1.Cells[0,0]:='i / j';
for i:=1 to n do
begin
StringGrid1.Cells[0,i]:=IntToStr(i);
StringGrid1.Cells[i,0]:=IntToStr(i);
end;
StringGrid2.ColCount:=2;
StringGrid2.Cells[0,0]:='i';
StringGrid2.RowCount:=n+1;
StringGrid2.Cells[1,0]:='b[ i ]';
for i:=1 to n do StringGrid2.Cells[0,i]:=IntToStr(i);
StringGrid3.ColCount:=n+1;
StringGrid3.RowCount:=2;
StringGrid3.Cells[0,0]:='i';
StringGrid3.Cells[0,1]:='x[ i ]';
end;
procedure TForm1.BitBtn3Click(Sender: TObject);
var i:integer;
begin
for i:=1 to n do
begin
StringGrid1.Cols[i].Clear;
StringGrid1.Rows[i].Clear;
StringGrid2.Cols[i].Clear;
StringGrid2.Rows[i].Clear;
StringGrid3.Cols[i].Clear;
end;
end;
end.
No comments:
Post a Comment
Kalau berkenan, dikoment donk untuk menjadi masukan buad Admin