Tuesday, May 19, 2009

Program Penyulihan Maju

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.

Sunday, May 3, 2009

Praktikum Metode Numerik 4.1 dan 4.2



type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
GroupBox3: TGroupBox;
Label1: TLabel;
StringGrid1: TStringGrid;
Button1: TButton;
Label2: TLabel;
Edit1: TEdit;
Button2: TButton;
Button3: TButton;
BitBtn1: TBitBtn;
StringGrid2: TStringGrid;
RadioGroup1: TRadioGroup;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
ordo:integer;
A,L:array[1..100,1..100]of real;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var i,j,k:integer; m:real;
begin
groupbox3.Visible:=true;
if radiogroup1.ItemIndex=0 then
begin
for i:=1 to ordo do
for j:=1 to ordo do
begin
A[i,j]:=strtofloat(stringgrid1.Cells[j,i]);
if i<>j then
L[i,j]:=0
else
L[i,j]:=1;
end;
for k:=1 to ordo-1 do
for i:=k+1 to ordo do
begin
m:=A[i,k]/A[k,k];
L[i,k]:=m;
for j:=k to ordo do
begin
A[i,j]:=A[i,j]-m*A[k,j];
end;
end;
stringgrid2.RowCount:=ordo+1;
stringgrid2.ColCount:=ordo+1;
stringgrid2.Cells[0,0]:='i,j';
for i:=1 to ordo do
begin
stringgrid2.Cells[0,i]:=inttostr(i);
stringgrid2.Cells[i,0]:=inttostr(i);
end;
for i:=1 to ordo do
for j:=1 to ordo do
stringgrid2.Cells[j,i]:=copy(floattostr(L[i,j]),1,5);
end
else if radiogroup1.ItemIndex=1 then
begin
for i:=1 to ordo do
for j:=1 to ordo do
A[i,j]:=strtofloat(stringgrid1.Cells[j,i]);
for k:=1 to ordo do
for i:=k+1 to ordo do
begin
m:=A[i,k]/A[k,k];
for j:=k to ordo do
begin
A[i,j]:=A[i,j]-m*A[k,j];
end;
end;
stringgrid2.RowCount:=ordo+1;
stringgrid2.ColCount:=ordo+1;
stringgrid2.Cells[0,0]:='i,j';
for i:=1 to ordo do
begin
stringgrid2.Cells[0,i]:=inttostr(i);
stringgrid2.Cells[i,0]:=inttostr(i);
end;
for i:=1 to ordo do
for j:=1 to ordo do
stringgrid2.Cells[j,i]:=copy(floattostr(A[i,j]),1,5);
end
else
begin
application.MessageBox('Tentukan jenis Matrix yang akan dipakai!','Message',MB_OK +MB_ICONWARNING);
groupbox3.Visible:=false;
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var i:integer;
begin
groupbox2.Visible:=true;
stringgrid1.Visible:=true;
ordo:=strtoint(edit1.Text);
stringgrid1.ColCount:=ordo+1;
stringgrid1.RowCount:=ordo+1;
stringgrid1.Cells[0,0]:='i/j';
for i:=1 to ordo do
begin
stringgrid1.Cells[0,i]:=inttostr(i);
stringgrid1.Cells[i,0]:=inttostr(i);
end;
end;

procedure TForm1.Button3Click(Sender: TObject);
var i:integer;
begin
for i:=1 to ordo do
stringgrid1.Rows[i].Clear;
edit1.Clear;
groupbox2.Visible:=false;
groupbox3.Visible:=false;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
groupbox2.Visible:=false;
groupbox3.Visible:=false;
end;

end.