0% found this document useful (0 votes)
99 views4 pages

Bisection PASCAL

The document describes a program that uses the bisection and linear interpolation methods to find the root of a function. It defines variables for the iterations, values of x and f(x), endpoints a and b, and midpoint c. It then displays menus to select the bisection or interpolation method. For either method, it calculates the function values at a, b, and c and iterates until the endpoints converge within a tolerance.

Uploaded by

Hassan Assaqaf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views4 pages

Bisection PASCAL

The document describes a program that uses the bisection and linear interpolation methods to find the root of a function. It defines variables for the iterations, values of x and f(x), endpoints a and b, and midpoint c. It then displays menus to select the bisection or interpolation method. For either method, it calculates the function values at a, b, and c and iterates until the endpoints converge within a tolerance.

Uploaded by

Hassan Assaqaf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

program Mebipol;

uses crt;
var iterasi,g,x,fx,a,b,c,fa,fb,fc:real;
pil:char;
const e=2.71;
eps=0.1;
begin
writeln(' +++++++++++++++++++++++++++');
writeln(' Metode :');
writeln(' +++++++++++++++++++++++++++');
writeln(' 1. Metode Bisection');
writeln(' 2. Metode Interpolasi Linier');
write('Pilih metode =');readln(pil);
writeln(' ');
writeln(' ');
case pil of
'1':begin
writeln('======================================');
writeln(' PROGRAM BISECTION');
writeln('======================================');
writeln('F(x) = 2x3 -12x2 -51x +3 +e2');
write('Masukkan x1 =');readln(a);
write('Masukkan x2 =');readln(b);
writeln(' a b c fa fb fc');
writeln('---------------------------------------------------');
repeat
c:=(a+b)/2;
fc:=(2*c*c*c)-(12*c*c)-(51*c)+3+(e*e);
x:=a;
fa:=(2*x*x*x)-(12*x*x)-(51*x)+3+(e*e);
fa:=fx;
x:=b;
fx:=(2*x*x*x)-(12*x*x)-(51*x)+3+(e*e);
fb:=fx;
x:=c;
fx:=(2*x*x*x)-(12*x*x)-(51*x)+3+(e*e);
fc:=fx;
g:=b-a;
writeln(a:2:2,b:10:2,c:10:2,fa:10:2,fb:10:2,fc:10:2);
if g<0 then g:=g*-1;
if fa*fb<0 then b:=c
else
a:=c
until g<eps;
end;
'2':begin
writeln('======================================');
writeln(' PROGRAM INTERPOLASI LINIER');
writeln('======================================');
writeln('F(x) = 2x3 -12x2 -51x +3 +e2');
write('Masukkan x1 =');readln(a);
write('Masukkan x2 =');readln(b);
writeln(' a b c fa fb fc');
writeln('---------------------------------------------------');
repeat
x:=a;
fa:=(2*x*x*x)-(12*x*x)-(51*x)+3+(e*e);
fa:=fx;
x:=b;
fx:=(2*x*x*x)-(12*x*x)-(51*x)+3+(e*e);
fb:=fx;
c:=(b-((fb*(b-a))/(fb-fa)));
x:=c;
fx:=(2*x*x*x)-(12*x*x)-(51*x)+3+(e*e);
fc:=fx;
g:=b-a;
writeln(a:2:2,b:10:2,c:10:2,fa:10:2,fb:10:2,fc:10:2);
if g<0 then g:=g*-1;
if fa*fb<0 then b:=c
else
a:=c
until g<eps;
end;
else
writeln('inputan salah');
end;
end.
START

var iterasi,g,x,fx,a,b,c,fa,fb,fc:real;
const e=2.71; eps=0.1;

writeln(' +++++++++++++++++++++++++++');
writeln(' Metode :');
writeln(' +++++++++++++++++++++++++++');
writeln(' 1. Metode Bisection');
writeln(' 2. Metode Interpolasi Linier');
write('Pilih metode =');readln(pil);
writeln(' ');
writeln(' ');

NO NO
case pil of
'2':begin else
'1':begin
YES

YES
YES writeln('inputan salah');

writeln('===========================');
writeln('============================'); writeln(' PROGRAM INTERPOLASI LINIER');
writeln(' PROGRAM BISECTION'); writeln('===========================');
writeln('============================'); writeln('F(x) = 2x3 -12x2 -51x +3 +e2');
writeln('F(x) = 2x3 -12x2 -51x +3 +e2'); write('Masukkan x1 =');readln(a);
write('Masukkan x1 =');readln(a); write('Masukkan x2 =');readln(b);
write('Masukkan x2 =');readln(b); writeln(' a b c fa fb fc');
writeln(' a b c fa fb fc'); writeln('---------------------------------------------');
writeln('----------------------------------------------');

repeat
repeat

x:=a;
c:=(a+b)/2; fa:=(2*x*x*x)-(12*x*x)-(51*x)+3+(e*e);
fc:=(2*c*c*c)-(12*c*c)-(51*c)+3+(e*e); fa:=fx;
x:=a; x:=b;
fa:=(2*x*x*x)-(12*x*x)-(51*x)+3+(e*e); fx:=(2*x*x*x)-(12*x*x)-(51*x)+3+(e*e);
fa:=fx; fb:=fx;
x:=b; c:=(b-((fb*(b-a))/(fb-fa)));
fx:=(2*x*x*x)-(12*x*x)-(51*x)+3+(e*e); x:=c;
fb:=fx; fx:=(2*x*x*x)-(12*x*x)-(51*x)+3+(e*e);
x:=c; fc:=fx;
fx:=(2*x*x*x)-(12*x*x)-(51*x)+3+(e*e); YES
g:=b-a;
YES fc:=fx;
g:=b-a;
writeln(a:2:2,b:10:2,c:10:2,fa:10:2,fb:10:2,fc:10:2);
writeln(a:2:2,b:10:2,c:10:2,fa:10:2,fb:10:2,fc:10:2);

NO NO
if g<0 t if fa*fb<0 else
NO NO
if g<0 t if fa*fb<0 else
YES YES YES

YES YES YES


g:=g*-1; b:=c; a:=c;
g:=g*-1; b:=c; a:=c;

until g<eps;
until g<eps;

END

You might also like