Blogger Widgets Seikat Ilmu: Metode Secant (Komputasi Numerik)
Dream Believe and Make it Happen

Jumat, 11 Juli 2014

Metode Secant (Komputasi Numerik)

 KOMPUTASI NUMERIK
 Modul Tutorial Pembelajaran
 Metode Secant 


 
                                                      


Oleh:
Zumrotus Sholehah
(12012609)



SEKOLAH TINGGI TEKNOLOGI NURUL JADID
PAITON PROBOLINGGO
2014


METODE  SECANT

  Buatlah tampilan form pada Borland Delphi seperti berikut:


Komponen dan Propertis :
Form      = Caption     : Metode Secant                    Edit 1    = text    : -
Label 1   = Caption     : Metode Secant                                    name  : eX1
Label 2   = Caption     : Nilai X1                              Edit 2   = text     : -
Label 3   = Caption     : Nilai X0                                              name  : eX0
Label 4   = Caption     : Batas Iterasi                        Edit 3   = text     : -
                                                                                                  name  : ebatas
Button 1  =  text        : &Secant
                    name      :  bSecant
Button 2  =  text         : &ulang 
                    name      : bulang
Button 3  =  text         : &Exit
                    name      : bexit
Untuk StringGrid ada pada tab control Additional,kemudian atur beberapa  propertis
sebagai berikut:
  FixedCols    = 0
  FixedRows  = 1
  ColCount     = 3
  RowCount   = 20

  Kemudian prosedur FormShow pada Form, ketikkan kode di antara Begin dan End, sebagai berikut:   Prosedur FormShow bisa ditemukan di Form >>Event >>OnShow
//membuat tampilan awal di kolom pada stringgrid
Procedure Tform1.FormShow(Sender: Tobject);
 begin
     with StringGrid1 do
     begin
          Cells[0,0] := ‘No’;
          Cells[1,0] := ‘Akar’;
          Cells[2,0] := ‘Kesalahan Iterasi’;
     end;
end;
Buatlah prosedur tak standar berikut:
//membuat sebuah fungsi pangkat
Function XPangkat (x:real; n:integer):real;
var
          i:integer;
          hasil:real;
begin
          hasil:=1;
          For i:= 1 to n do
          hasil:=hasil*x;
          result:=hasil;
end;
Buatlah prosedur tak standar berikut:
           //membuat sebuah fungsi Faktorial
Function Faktorial (n:integer):integer;
var
          i,hasil:integer;
begin
          hasil:=1;
          if n = 0 then hasil := 1 else
          for i:=1 to n do
               hasil:=hasil*i;
               result:=hasil;
end;
  Buatlah prosedur standar pada tombol Secant ,ketikkan kode di antara Begin
dan End, sebagai berikut :
var
j: Integer;
begin
//mengambil inputan
xi:=StrToFloat(edXi.Text);
xi1:=StrToFloat(edXi1.Text);
eibatas:=StrToFloat(edbatasiterasi.Text);
//cari nilai fungsi (x)
fxi:=exp(-xi)-xi;
//cek kondisi fungsi(x)
if fxi=0 then
begin
  akar:=xi;
  with StringGrid1 do
  begin
  Cells[0,1]:='1';
  Cells[1,1]:=FloatToStr(akar);
  Cells[2,1]:=FloatToStr(salah);
  end;
  exit;
  end;
else
j:=1;
repeat
akardugaawal:=xi;

//cari nilai fungsi (xi1)
fxi1:=exp(-xi1)-xi1;

//rumus secant
xi:=xi-(fxi*(xi1-xi))/(fxi1-fxi);

//cari fungsi (xi)
fxi:=exp(-xi)-xi;

//cek kondisi fungsi
if fxi=0 then
begin
akar:=xi;
With StringGrid1 do
begin
  Cells[0,0]:='1';
  Cells[1,1]:=FloatToStr(akar);
  Cells[2,1]:=FloatToStr(salah);
end;
exit;
end;

akarduga:=xi;
salah:=abs((akarduga-akardugaawal)/akarduga)*100;
with StringGrid1 do
begin
  Cells[0,j]:=IntToStr(j);
  Cells[1,j]:=FloatToStr(akarduga);
  Cells[2,j]:=FloatToStr(salah);
              end;
StringGrid1.RowCount:=j+1;
xi1:=akardugaawal;
j:=j+1;
until salah<=eibatas;
end;
  Kemudian pada tombol Ulang, ketikkan kode di antara Begin dan
            End, sebagai berikut:
procedure TForm1.bUlangClick(Sender: TObject);
var i,j : Integer;
begin
    StringGrid1.RowCount:=2;
    for i := 1 to 20 do
    for j := 1 to 3 do
         StringGrid1.Cells[j-1,i]:='';
end;
  Kemudian pada tombol Exit, ketikkan kode di antara Begin dan
            End, sebagai berikut:
procedure TForm1.bExitClick(Sender: TObject);
begin
if Application.MessageBox('Apakah anda mau keluar?','12012609',32+4)=6 then
Application.Terminate;
end;
end.
  Kemudian jalankan program dengan menekan F9.

SEMOGA BERMANFAAT

Tidak ada komentar:

Posting Komentar