Anda di halaman 1dari 17

PENJELASAN PENCARIAN AKAR DARI

X4 + 3X3 + 2X2 + 5X = 0
DENGAN MENGGUNAKAN METODE SECANT

Nama : PUTU RUSDI ARIAWAN


NIM : 0804405050

JURUSAN TEKNIK ELEKTRO


FAKULTAS TEKNIK
UNIVERSITAS UDAYANA
PROGRAM METODE SECANT

A. Flowchart Program

START

Input x1

Y1x14 + 3* x13 + 2*x12 + 5*x

Input x2

Y2x24 + 3* x23 + 2*x22 + 5*x2

X3 x2 – (Y2*(x2 – x1)/(Y2 – Y1))

Y3x34 + 3* x33 + 2*x32 + 5*x3

tidak
Y1*Y3 < 0

ya
X1X3
X2 X3
Y1 Y3
Y2 Y3

tidak
Abs(Y3) < 10-8

ya

Output Y3
dan X3

ya
Coba Lagi?

tidak
STOP

PUTU RUSDI ARIAWAN


B. Syntax Program
program secant;
uses wincrt;
var
x1,x2,x3,y1,y2,y3 : real;
i,j, code : integer;
a : char;
x1s, x2s : string;

Procedure delay;

Var
Wkt : longint;

Begin
For Wkt := 1 to 10000000 do
Write('');
End;

procedure mulai;
begin
GotoXY (15,1);
WriteLn
('**************************************************');
GotoXY (15,2);
WriteLn ('**');
GotoXY (63,2);
WriteLn ('**');
GotoXY (15,3);
WriteLn ('**');
GotoXY (63,3);
WriteLn ('**');
GotoXY (15,4);
WriteLn ('**');
GotoXY (63,4);
WriteLn ('**');
GotoXY (15,5);
WriteLn ('**');
GotoXY (63,5);
WriteLn ('**');
GotoXY (15,6);
WriteLn
('**************************************************');
GotoXY (29,3);
WriteLn ('PENCARIAN AKAR-AKAR DARI');
GotoXY (30,4);
WriteLn ('X^4 + 3X^3 + 2X^2 + 5X');
GotoXY (1,8);
WriteLn
('*******************************************************************
*************');
end;

procedure start;
begin
GotoXY (30,10);
WriteLn ('***************************');
GotoXY (29,11);

PUTU RUSDI ARIAWAN


WriteLn ('**');
GotoXY (56,11);
WriteLn ('**');
GotoXY (25,12);
WriteLn ('*****');
GotoXY (57,12);
WriteLn ('*****');
GotoXY (29,13);
WriteLn ('**');
GotoXY (56,13);
WriteLn ('**');
GotoXY (30,14);
WriteLn ('***************************');
GotoXY (37,12);
WriteLn ('METODE SECANT');

end;

procedure stop;
begin
GotoXY (30,10);
WriteLn ('***************************');
GotoXY (29,11);
WriteLn ('**');
GotoXY (56,11);
WriteLn ('**');
GotoXY (25,12);
WriteLn ('*****');
GotoXY (57,12);
WriteLn ('*****');
GotoXY (29,13);
WriteLn ('**');
GotoXY (56,13);
WriteLn ('**');
GotoXY (30,14);
WriteLn ('***************************');
GotoXY (38,12);
WriteLn ('TERIMA KASIH');

end;

procedure input1;

begin
val (x1s, x1, code);
if (code <> 0)then
begin
GotoXY (5,11);
Writeln ('Maaf, Input Harus Berupa Angka');
j := 0;
end
else
if (x1 < -7) or (x1 > 7)then
begin
GotoXY (5,11);
writeln(' Masukkan nilai tebakan x1 antara -7 s/d 7');
j := 0;
end
else
if (x1 = 0) then
begin

PUTU RUSDI ARIAWAN


GotoXY (5,11);
writeln(' Nilai Tebakan X1 Tidak Boleh Nol');
j := 0;
end
else
j := 1;
end;

procedure input2;

begin
val (x2s, x2, code);
if (code <> 0)then
begin
GotoXY (5,11);
Writeln ('Maaf, Input Harus Berupa Angka');
j := 0;
end
else
if (x2 < -7) or (x2 > 7)then
begin
GotoXY (5,11);
writeln(' Masukkan Nilai Tebakan X2 Antara -7 s/d 7');
j := 0;
end
else
if (x2 = 0) then
begin
GotoXY (5,11);
writeln(' Nilai Tebakan X2 Tidak Boleh Nol');
j := 0;
end
else
j := 1;
end;

procedure input3 ;
begin
if (x1 = x2) then
begin
repeat
GotoXY (5,11);
writeln(' Nilai Kedua Tebakan Harus Berbeda');
repeat
mulai;
GotoXY (5,9);
write ('Masukkan Nilai X1 = ');
readln(x1s);
clrscr;
input1;
until j = 1;
repeat
mulai;
GotoXY (5,9);
write ('Masukkan Nilai X2 = ');
readln(x2s);
clrscr;
input2;
until j = 1;
if (x1> 0) and (x2 < 0) then

PUTU RUSDI ARIAWAN


begin
repeat
GotoXY (5,11);
writeln(' Nilai X2 Harus Positif');
repeat
mulai;
GotoXY (5,9);
write ('Masukkan Nilai X2 = ');
readln(x2s);
clrscr;
input2;
until j = 1;
until x2 > 0
end;
until (x1 <> x2)
end
else
if (x1> 0) and (x2 < 0) then
begin
repeat
GotoXY (5,11);
writeln(' Nilai X2 Harus Positif');
repeat
mulai;
GotoXY (5,9);
write ('Masukkan Nilai X2 = ');
readln(x2s);
clrscr;
input2;
until j = 1;
until x2 > 0
end;
end;

{program utama}
begin
clrscr;
start;
delay ;
repeat
clrscr;
mulai;
repeat
GotoXY (5,9);
write ('MASUKKAN NILAI TEBAKAN X1 = ');
readln(x1s);
clrscr;
mulai;
input1;
until j = 1;
repeat
GotoXY (5,9);
write ('MASUKKAN NILAI TEBAKAN X2= ');
readln(x2s);
clrscr;
mulai;
input2;
until j = 1 ;

input3;

PUTU RUSDI ARIAWAN


WriteLn('=============================================
==============================');
WriteLn(' N X f(X)
Error ');
WriteLn('=============================================
==============================');
y1:= x1*x1*x1*x1 + 3*x1*x1*x1 + 2*x1*x1 + 5*x1;

y2:= x2*x2*x2*x2 + 3*x2*x2*x2 + 2*x2*x2 + 5*x2;


writeln;

begin
repeat
begin
i:= i+1;
x3:= x2 - (y2 * ( x2 - x1) / (y2 -y1 ));
y3:= x3*x3*x3*x3 + 3*x3*x3*x3 + 2*x3*x3 + 5*x3;
WriteLn(' |',i,'| ',x3,' | ',y3,'| ', Abs(
y3 ),' |');
if ( y1*y3 ) < 0 Then
Begin
x2:= x3;
y2:=y3;
End
Else
Begin
x1:= x3;
y1:=y3;
End;
End;
Until abs (y3) < 1E-08 ;

WriteLn('============================================================
=================');

WriteLn('===================================================');
WriteLn(' AKAR PERSAMAANNYA ADALAH = ', x3);
WriteLn(' NILAI ERRORNYA ADALAH = ', Abs(y3) );
WriteLn('===================================================');
WriteLn;
end;

write(' Coba Lagi = y /t ?');


a := readkey;
Until upcase (a) <>'Y';
clrscr;
stop;
delay;
donewincrt;
end.

PUTU RUSDI ARIAWAN


C. Procedure Yang Digunakan Pada Program
Program di atas merupakan program untuk mencari akar-akar dari persamaan :

X4 + 3X3 + 2X2 + 5X = 0

dengan menggunakan metode SECANT. Dalam program ini terdapat 7 subprogram


yang menggunakan procedure dan sebuah program utama. Berikut adalah fungsi atau
kegunaan dari setiap procedure yang dibuat:

1. Procedure Delay.
Procedure delay;

Var
Wkt : longint;

Begin
For Wkt := 1 to 10000000 do
Write('');
End;

Procedure ini digunakan untuk menyisipkan waktu jeda, dan akan digunakan
pada program utama.

2. Procedure Mulai, Start dan Stop


procedure mulai;
begin
GotoXY (15,1);
WriteLn
('**************************************************');
GotoXY (15,2);
WriteLn ('**');
GotoXY (63,2);
WriteLn ('**');
GotoXY (15,3);
WriteLn ('**');
GotoXY (63,3);
WriteLn ('**');
GotoXY (15,4);
WriteLn ('**');
GotoXY (63,4);
WriteLn ('**');
GotoXY (15,5);
WriteLn ('**');
GotoXY (63,5);
WriteLn ('**');
GotoXY (15,6);
WriteLn
('**************************************************');
GotoXY (29,3);
WriteLn ('PENCARIAN AKAR-AKAR DARI');
GotoXY (30,4);

PUTU RUSDI ARIAWAN


WriteLn ('X^4 + 3X^3 + 2X^2 + 5X');
GotoXY (1,8);
WriteLn
('*******************************************************************
*************');
end;

procedure start;
begin
GotoXY (30,10);
WriteLn ('***************************');
GotoXY (29,11);
WriteLn ('**');
GotoXY (56,11);
WriteLn ('**');
GotoXY (25,12);
WriteLn ('*****');
GotoXY (57,12);
WriteLn ('*****');
GotoXY (29,13);
WriteLn ('**');
GotoXY (56,13);
WriteLn ('**');
GotoXY (30,14);
WriteLn ('***************************');
GotoXY (37,12);
WriteLn ('METODE SECANT');

end;

procedure stop;
begin
GotoXY (30,10);
WriteLn ('***************************');
GotoXY (29,11);
WriteLn ('**');
GotoXY (56,11);
WriteLn ('**');
GotoXY (25,12);
WriteLn ('*****');
GotoXY (57,12);
WriteLn ('*****');
GotoXY (29,13);
WriteLn ('**');
GotoXY (56,13);
WriteLn ('**');
GotoXY (30,14);
WriteLn ('***************************');
GotoXY (38,12);
WriteLn ('TERIMA KASIH');
end;

Procedure-procedure ini digunakan untuk membuat tampilan-tampilan seperti


yang tertulis pada masing-masing procedure tersebut pada saat program dijalankan.
Procedure ini digunakan pada program utama.

PUTU RUSDI ARIAWAN


3. Procedure Input1.
procedure input1;

begin
val (x1s, x1, code);
if (code <> 0)then
begin
GotoXY (5,11);
Writeln ('Maaf, Input Harus Berupa Angka');
j := 0;
end
else
if (x1 < -7) or (x1 > 7)then
begin
GotoXY (5,11);
writeln(' Masukkan nilai tebakan x1 antara -7 s/d 7');
j := 0;
end
else
if (x1 = 0) then
begin
GotoXY (5,11);
writeln(' Nilai Tebakan X1 Tidak Boleh Nol');
j := 0;
end
else
j := 1;
end;

Procedure ini digunakan untuk membatasi input X1 yang dimasukkan oleh


pengguna program, sehingga program tidak menjadi error. Procedure ini digunakan
pada procedure input3 dan pada program utama.

4. Procedure Input2.
procedure input2;

begin
val (x2s, x2, code);
if (code <> 0)then
begin
GotoXY (5,11);
Writeln ('Maaf, Input Harus Berupa Angka');
j := 0;
end
else
if (x2 < -7) or (x2 > 7)then
begin
GotoXY (5,11);
writeln(' Masukkan Nilai Tebakan X2 Antara -7 s/d 7');
j := 0;
end
else
if (x2 = 0) then
begin
GotoXY (5,11);

PUTU RUSDI ARIAWAN


writeln(' Nilai Tebakan X2 Tidak Boleh Nol');
j := 0;
end
else
j := 1;
end;

Procedure ini digunakan untuk membatasi input X2 yang dimasukkan oleh


pengguna program, sehingga program tidak menjadi error. Procedure ini digunakan
pada procedure input3 dan pada program utama.

5. Procedure Input3.
procedure input3 ;
begin
if (x1 = x2) then
begin
repeat
GotoXY (5,11);
writeln(' Nilai Kedua Tebakan Harus Berbeda');
repeat
mulai;
GotoXY (5,9);
write ('Masukkan Nilai X1 = ');
readln(x1s);
clrscr;
input1;
until j = 1;
repeat
mulai;
GotoXY (5,9);
write ('Masukkan Nilai X2 = ');
readln(x2s);
clrscr;
input2;
until j = 1;
if (x1> 0) and (x2 < 0) then
begin
repeat
GotoXY (5,11);
writeln(' Nilai X2 Harus Positif');
repeat
mulai;
GotoXY (5,9);
write ('Masukkan Nilai X2 = ');
readln(x2s);
clrscr;
input2;
until j = 1;
until x2 > 0
end;
until (x1 <> x2)
end
else
if (x1> 0) and (x2 < 0) then
begin
repeat

PUTU RUSDI ARIAWAN


GotoXY (5,11);
writeln(' Nilai X2 Harus Positif');
repeat
mulai;
GotoXY (5,9);
write ('Masukkan Nilai X2 = ');
readln(x2s);
clrscr;
input2;
until j = 1;
until x2 > 0
end;
end;

Procedure ini digunakan untuk membatasi input X1 dan X2 yang dimasukkan


oleh pengguna program, sehingga kesalahan perhitungan dalam program menjadi
lebih kecil dan agar program tidak menjadi error. Procedure ini digunakan pada
program utama.

D. Uji Coba Dan User Interface


Setelah program dijalankan, pada masukkan X1 jika :
a. Diinputkan nilai 0 maka program akan meminta penginputan lagi dan akan tampil
dilayar :

PUTU RUSDI ARIAWAN


b. Diinputkan selain angka maka program akan meminta penginputan lagi dan akan
tampil di layar :

c. Diinputkan angka yang lebih dari nilai -7 s/d 7 maka program akan meminta
penginputan lagi dan akan tampil di layar :

Dan jika nilai yang diinputkan sesuai dengan permintaan program tidak
melewati aturan-aturan yang telah diset dalam program, maka program akan meminta

PUTU RUSDI ARIAWAN


penginputan nilai X2. Pada penginputan nilai X2 batasan-batasannya sama dengan
pada penginputan X1 dan ditambah dengan 2 batasan lagi, yaitu :

a. Jika nilai input X2 sama dengan nilai input X1 maka akan tampil di layar :

Dan program akan meminta penginputan ulang X1 dan X2.


b. Jika nilai X1 yang diinputkan bilangan positif, sedangkan nilai X2 diinputkan
bilangan negative maka akan tampil di layar :

PUTU RUSDI ARIAWAN


Dan program akan meminta penginputan ulang X2.
Jika penginputan X1 dan X2 sesuai dengan batasan-batasan yang telah
ditentukan oleh program dan mendapatkan nilai akar persamaan dan nilai errornya
maka pada pilihan terakhir terdapat pilihan untuk mengulang perhitungan. Jika ingin
mengulang tekan tombol ‘Y’ dan jika tidak tekan sembarang tombol untuk menutup
program.

Uji Coba :
Input X1 : 1
Input X2 : 2
Outputnya :

Langkah-langkahnya seperti pada gambar berikut ini :

Langkah 1.

PUTU RUSDI ARIAWAN


Langkah 2.

Langkah 3.

PUTU RUSDI ARIAWAN


BIODATA PENULIS

Nama : Putu Rusdi Ariawan

TTL : Denpasar. 19 April 1990

Agama : Hindu

Mahasiswa Teknik Elektro Unv. Udayana

Email : turusdi.info@gmail.com

www.facebook.com/turusdi

PUTU RUSDI ARIAWAN

Anda mungkin juga menyukai