FAKULTAS TEKNIK
UPN “VETERAN” JAWA TIMUR
Nama : BETA CAHAYA PERTIWI
Praktikum : MATEMATIKA TEKNIK NPM/Semester : 1631010086 / IV
Percobaan : BAB 2. AKAR PERSAMAAN Sesi : VII
Tanggal : 01 MARET 2018 Paralel :C
Pembimbing : IR. KINDRIARI NURMA W, MT
LAPORAN RESMI
Soal :
1. Buatlah Algoritma perhitungan manual dari Metode Akar Persamaan, Metode
Setengah Interval (Bisection), Metode Interpolasi Linier, Metode Newton Rhapson,
Metode Secant, dan Metode Iterasi.
2. Kerjakan soal dibawah ini :
a. Buatlah program MATLAB yang berisikan perhitungan Akar Persamaan, Metode
Setengah Interval (Bisection), Metode Interpolasi Linier, Metode Newton Rhapson,
Metode Secant, dan Metode Iterasi dengan ketentuan sebagai berikut :
Dalam satu program
Gunakan 1 jenis statement pemilihan kondisi
Gunakan 3 jenis statement perulangan
Persamaan berupa Input yang terbaca oleh statement syms
Tabelkan hasil perulangan dengan rapi
Kerjakan dengan urutan : Algoritma, Flowchart, Script, Hasil Run
b. Buatlah program PASCAL yang berisikan perhitungan Akar Persamaan, Metode
Setengah Interval (Bisection), Metode Interpolasi Linier, Metode Newton Rhapson,
Metode Secant, dan Metode Iterasi dengan ketentuan sebagai berikut :
Pilih hanya 2 macam metode saja
Gunakan deklarasi fungsi dalam mengerjakan program
Tabelkan hasil perulangan dengan rapi
Kerjakan dengan urutan : Algoritma, Flowchart, Script, Hasil Run
3. Sebuah Percobaan mengenai dekomposisi dari zat A dalam sebuah reactor
bertekanan yang beroperasi secara batch menunjukkan reaksi yang berbeda pada
tiap temperature.
Pada temperature 2 – 5 oC, −𝑟𝐴 = 2.3 𝑃2𝐴 + 3 𝑃𝐴 − 11 .
Jika suhu adalah x1 dan x2, dan −𝑟𝐴 adalah f(𝑥) dimana 𝑃𝐴 = 𝑥, hitunglah
persamaan diatas dengan menggunakan metode :
11
a. Bisection
b. Interpolasi Linier
Kerjakan dengan mengubah temperature hingga sesuai dengan ketentuan Metode
Interpolasi Linier dan Bisection.
4. Kerjakan soal berikut ini :
a. Udara pada tekanan 1 bar dan suhu 25oC masuk kompresor pada kecepatan rendah,
keluar dari kompresor memiliki tekanan 3 bar. Udara yang keluar dari kompresor
dialirkan ke nozzle dimana terjadi proses expansi sehingga kecepatan akhir dari
udara keluar adalah 600 m s-1 pada tekanan dan suhu tertentu. Jika usaha yang
dibutuhkan untuk mengkompresi udara adalah 240 kJ per kg udara, berapa banyak
panas yang harus dibuang pada saat proses kompresi?
Persamaan yang digunakan adalah sbb :
𝑢22
𝑄= − 𝑊𝑠
2
Jika Q = f(x) , Ws = konstanta perhitungan dan 𝑢22 = x , selesaikan persamaan diatas
menggunakan metode Iterasi dengan dengan minimal perhitungan hasil iterasi 10
kali.
b. Reaksi Kesetimbangan
Dalam Suatu Proses Teknik Kimia, Campuran Karbon Monoksida Dan Oksigen
Mencapai Kesetimbangan Pada Suhu 300oK Dan Tekanan 5 Atm. Reaksi
Teiritisnya Adalah
CO + 0.5 O2 CO2 (1)
Reaksi kimia yang sebenarnya terjadi dapat ditulis sebagai berikut :
CO + O2 xCO2 + (1+X)/2 O2 + (1-X) CO2
Persamaan kesetimbangan kimia untuk menentukan fraksi mol CO yang tersisa
yaitu x, ditulis sebagai
(1−𝑥)(3+𝑥)1/2
𝐾𝑝 = , 0<X<1
𝑥(𝑥+1)1/2 𝑃 1/2
12
c. Sebuah reaksi orde du terjadi dalam reactor model dinamik untuk isothermal dan
𝑑𝐶𝐴 𝐹 𝐹
volume konstan dengan persamaan = 𝐶 − 𝐶 − 𝐾𝐶𝐴 2 , tentukan
𝑑𝑡 𝑉 𝐴𝐹 𝑉 𝐴
konsentrasi (𝐶𝐴 ) pada steady state dengan parameter harga F/V = 1/Menit, 𝐶𝐴𝐹 = 1
gmol/L dan K = 1 L/gmol.menit dengan menggunakan metode setengah interval
(Bisection) (NPM GENAP) dan metode interpolasi linier (NPM GANJIL)
13
Jawaban:
1. Algoritma setiap metode
- Metode Akar Persamaan Kuadrat
1. Input persamaan kuadrat
2. Tentukan a, b, c
3. Hitung deteminan dengan rumus d=(b^2)-(4*a*c)
4. Jika d>0 maka “Akar Riil”
Rumus akar persamaannya : x1,2=((-b)(d^0.5))/(2*a)
5. Jika d<0 maka “Akar Imajiner”
Rumus akar persamaannya : x1,2=((-b)/(2*a))((-b)-(d^0.5))/(2*a)
6. Jika d=0 maka “Akar Rasional”
Rumus akar persamaannya : x1=(-b)/(2*a) ; x2=x1
14
4. Jika f(x1)*f(x3) < 0 maka x2 = x3 (artinya titik x2 digantikan oleh
titik x3 yang berfungsi sebagai titik x2 pada iterasi berikutnya), jika
tidak maka x1 = x2, x2=x3.
5. Dari iterasi pertama kita memperoleh interval [x1,x2] yang baru dan
titik tengah x3 yang baru.
6. Cek lagi seperti sebelumnya hingga batas toleransi yang diinginkan.
- Metode Newton-Rhapson
1. Asumsikan nilai x1 sehingga diperoleh f(x1)
2. Turunkan persamaan f ’ (x) dan masukkan x1, sehingga diperoleh
f ‘ (x1)
3. Hitung x2:=x1 - [ f(x) / f ‘ (x) ] dan masukkan x1, sehingga
diperoleh f(x2)
4. Nilai x2 dari iterasi pertama digunakan pada iterasi berikutnya
sebagai x1 yang baru, maka di dapat nilai x2 yang baru.
5. Begitu seterusnya hingga batas toleransi yang diinginkan.
- Metode Secant
1. Asumsikan nilai x1 dan x2 sehingga diperoleh f(x1) dan f(x2)
2. Definisikan nilai x3 pada interval [x1,x2] yaitu x3:=x2-(fx2*(x2-
x1))/(fx2-fx1), masukkan ke persamaan sehingga diperoleh f(x3)
3. Nilai x2 dan x3 digunakan pada iterasi berikutnya sebagai x1 dan x2
yang baru sehingga diperoleh nilai x3 yang baru
4. Begitu seterusnya hingga batas toleransi yang diinginkan.
- Metode Iterasi
1. Asumsikan nilai x1
2. Persamaan f(x) = 0 diubah sehingga parameter x berada di sisi kiri
persamaan.
3. Masukkan nilai x1 ke persamaan yang telah diubah. Nilai ini
menjadi nilai x2.
15
2. Soal A, dan B
A.
- Algoritma
1. Memilih jenis perhitungan yang akan di gunakan
a. Metode Setengah Interval (Bisection)
- Input eq,x1,x2
- Menghitung eqx1,eqx2,eqxt,syms x
- Apabila perkalian eqx1 dengan eqx2 lebih dari 0, input x1
dan x2 kemudian menghitung eqx1 dan eqx2.
- Selain itu, menghitung nilai xt dan eqxt
- Output x1,x2,xt,eqx1,eqx2,eqxt
- Saat nilai eqxt lebih besar disbanding toleransi maka terdapat
dua pilihan,
1. Perkalian eqx1 dengan eqxt kurang dari nol, sehingga
nilai x2=xt dan eqxt=eqx2
2. Selain itu, x1=xt dan eqx1=eqxt
- Menghitung nilai xt dan eqxt
- Output x1,x2,xt,eqx1,eqx2,eqxt
b. Metode secant
- Input eq,x1,x2
- Menghitung syms x, fx1,fx2,fxt, dan xt
- Perulangan Iterasi
- Menghitung fx1,fx2,xt,fxt
- Output i,x1,x2,xt,fx1,fx2,fxt
c. Metode interpolasi linear
- Input eq,x1,x2, dan tol
- Menghitung fx1,fx2, syms x
- Apabila perkalian fx1 dengan fx2 lebih dari nol maka
1. Input x1,x2
2. Menghitung fx1, dan fx2
- Selain itu, menghtiung nilai xt dan fxt
16
- Output x1,x2,xt,fx1,fx2, dan fxt
- Saat nilai fxt lebih dari nol maka,
1. Perkalian antara fx1 dan fxt kurang dari nol, nilai x2 dan
xt sama, begitu pula fx2 dan fxt
2. Selain itu, nilai antara x1, fx1 dengan xt, fxt sama
- Menghitung nilai xt
- Output x1,x2,xt,fx1,fx2,fxt
d. Metode Newton Rhapson
- Input f1,x1, iteration
- Menghitung syms x, fx1,f2, fi, xt dan fxt
- Untuk iterasi dari 1 sampai dengan nilai yang diisi, maka
hitung nilai fx1,fi,xt, dan fxt
- Output i,x1,xt,fx1,fxt
e. Metode Iterasi
- Input toleransi, x1
- Menghitung x2 dan nilai koreksi
- Saat nilai koreksi lebih dari sama dengan toleransi maka
hitung x2,ea
- Output i,x1,x2,correction
17
- Flowchart
Start
Input pilihan
perhitungan
Biseksi no Secant no a
yes yes
Input
Input
eq,x1,x2
eq,x1,x2
xt=(x1+x2)/2 syms x
eqx1=subs(eq,x,x1); eqx2=subs(eq,x,x2);
eqxt=subs(eq,x,xt) Menghitung syms x,
fx1,fx2,fxt, dan xt
xt=(x1+x2)/2;
for
(eqx1*eqx2)>0 no eqxt=subs(eq,x,
i=1:1:it
xt);
yes
Menghitung
Input fx1,fx2,xt,fxt
x1,x2 yes
eqx1=subs(eq,x,x1);eqx2 Output
=subs(eq,x,x2); i,x1,x2,xt,fx1,f
x2,fxt
Output
x1,x2,xt,e
qx1,eqx2,e
qxt
End.
18
a Interpolasi Newton
no no Iteration
linear Rhapson
yes yes
Input Input
Input x1
eq,x1,x2, f1,x1,
dan tol iteration
For Output I,
i=1:1:it xi, xi+1
xt dan eration
If fx1*fx2>0; no
fxt
yes
while Ea>=E
fx1=subs(f1,x,x1);
Input yes fi=subs(f2,x,x1);
x1,x2 xt=x1-(fx1/fi); yes
fxt=subs(f1,x,xt);
x2=((-x1^2)+(3*x1)+3)^(1/
no );
Ea=abs(((x2-x1)/x2)*100);
fx1, dan fx2
Output
Output I,x1,x2
i,x1,xt,fx1, no
fxt
While
abs(fxt)>tol;
yes
x1=xt;
(fx1*fxt)<0
fx1=fxt;
no
x2=xt;
fx2=fxt;
xt=x2-(fx2/(fx2-
fx1))*(x2-x1)
Output
x1,x2,xt,fx
1,fx2,fxt
19
- Script
clear all;
clc;
disp('Hi peeps, you will probably know if we are doing discussion');
disp(' I got 5 ways to solve those problems, we can using...');
disp('1. Bisection');
disp('2. Secant');
disp('3. Linear Interpolation');
disp('4. Newton und Raphson');
disp('5. Iteration');
ch=input('Choose wisely darling = ');
if ch==1
syms x;
disp('~~BISECTION~~');
eq=input('Enter the equation = ');
x1=input('input the first value of X = ');
x2=input('input the second value of X = ');
tol=input('Toleration? ');
xt=(x1+x2)/2;
eqx1=subs(eq,x,x1);
eqx2=subs(eq,x,x2);
eqxt=subs(eq,x,xt);
if (eqx1*eqx2)>0;
x1=input('input the first value of X = ');
x2=input('input the second value of X = ');
eqx1=subs(eq,x,x1);
eqx2=subs(eq,x,x2);
else
xt=(x1+x2)/2;
eqxt=subs(eq,x,xt);
end
20
disp('---------------------------------------------------------------------');
disp(' x1 x2 xt fx1 fx2 fxt');
disp('---------------------------------------------------------------------');
i=1;
fprintf(' %8.4f %5.4f %5.4f %5.4f %5.4f
%5.4f\n',x1,x2,xt,eqx1,eqx2,eqxt);
while abs(eqxt)>tol;
i=i+1;
if (eqx1*eqxt)<0
x2=xt;
eqx2=eqxt;
else
x1=xt;
eqx1=eqxt;
end
xt=(x1+x2)/2;
eqxt=subs(eq,x,xt);
fprintf(' %8.4f %5.4f %5.4f %5.4f %5.4f
%5.4f\n',x1,x2,xt,eqx1,eqx2,eqxt);
end
disp(' ');
if ch==2
syms x;
disp('~~SECANT METHOD~~');
eq=input('INPUT THE EQUATION = ');
x1=input('INPUT THE FIRST VALUE OF X = ');
x2=input('INPUT THE SECOND VALUE OF X = ');
it=input('HOW MANY DATA THAT YOU WANTED? ');
fx1=subs(eq,x,x1);
fx2=subs(eq,x,x2);
xt=x2-((fx2*(x2-x1))/(fx2-fx1));
21
fxt=subs(eq,x,xt);
disp('--------------------------------------------------------------------------------
-----');
disp(' iteration x1 x2 xt fx1 fx2 fxt');
disp('--------------------------------------------------------------------------------
-----');
for i=1:1:it
fx1=subs(f,x,x1);
fx2=subs(f,x,x2);
xt=x2-((fx2*(x2-x1))/(fx2-fx1));
fxt=subs(eq,x,xt);
fprintf(' %5.f %9.4f %3.4f %2.4f %4.4f %4.4f
%4.4f\n',i,x1,x2,xt,fx1,fx2,fxt);
x1=x2;
x2=xt;
end
disp(' ');
if ch==3
syms x;
disp('~~LINEAR INTERPOLATION~~');
eq=input('EQUATION PLEASE = ');
x1=input('INPUT THE VALUE OF FIRST X = ');
x2=input('INPUT THE VALUE OF SECOND X = ');
tol=input('TOLERATION? ');
fx1=subs(eq,x,x1);
fx2=subs(eq,x,x2);
if fx1*fx2>0;
x1=input('Masukkan nilai x1 yang lain = ');
x2=input('Masukkan nilai x2 yang lain = ');
fx1=subs(eq,x,x1);
fx2=subs(eq,x,x2);
22
else
xt=x2-(fx2/(fx2-fx1))*(x2-x1);
fxt=subs(eq,x,xt);
end
disp('---------------------------------------------------------------------');
disp(' x1 x2 xt fx1 fx2 fxt');
disp('---------------------------------------------------------------------');
i=1;
fprintf(' %8.4f %5.4f %5.4f %5.4f %5.4f
%5.4f\n',x1,x2,xt,fx1,fx2,fxt);
while abs(fxt)>tol;
i=i+1;
if (fx1*fxt)<0
x2=xt;
fx2=fxt;
else
x1=xt;
fx1=fxt;
end
xt=x2-(fx2/(fx2-fx1))*(x2-x1);
fxt=subs(eq,x,xt);
fprintf(' %8.4f %5.4f %5.4f %5.4f %5.4f
%5.4f\n',x1,x2,xt,fx1,fx2,fxt);
end
disp(' ');
if ch==4
syms x;
disp('~~Newton-Rhapson~~');
f1=input('EQUATION PLEASE= ');
x1=input('INPUT THE VALUE OF FIRST X= ');
23
iteration=input('HOW MANY ITERATION THAT YOU WANT TO?
');
fx1=subs(f1,x,x1);
f2=diff(f1);
fi=subs(f2,x,x1);
xt=x1-(fx1/fi);
fxt=subs(f1,x,xt);
disp('----------------------------------------------------------');
disp(' Iteration x1 x2 fx1 fx2');
disp('----------------------------------------------------------');
for i=1:1:iteration
fx1=subs(f1,x,x1);
fi=subs(f2,x,x1);
xt=x1-(fx1/fi);
fxt=subs(f1,x,xt);
fprintf(' %5.f %9.4f %4.4f %4.4f %4.4f\n',i,x1,xt,fx1,fxt);
x1=xt;
end
disp(' ');
if ch==5
E=0.001;
x1=input('masukkan nilai x1 = ');
x2=((-x1^2)+(3*x1)+3)^(1/3);
Ea=abs(((x2-x1)/x2)*100);
i=1;
disp('=============================================')
disp(' i xi xi+1 ')
disp('===============================================')
while Ea>=E
x1=x2;
x2=((-x1^2)+(3*x1)+3)^(1/3);
24
Ea=abs(((x2-x1)/x2)*100);
fprintf('%3.0f%15.6f%15.6f\n',i,x1,x2);
i=i+1;
end
end
end
end
end
end
25
- Hasil Run
a. Bisection
b. Secant
c. Interpolasi linear
26
d. Newton Rhapson
e. Iteration
27
B.
-Algoritma
a. Mendeklarasi variable integer, real dan label
b. Memilih antara biseksi dan secant
1.Biseksi
- Menentukan nilai I,a,b,n,I,fa, dan fb
- Saat nilai I kurang dari n, hitung x,fx
- Output I,a,x,b,fa,fb,fx
- Apabila perkalian fx dan fa kurang dari o maka nilai b=x dan fx=fb
- Selain itu nilai a=x, fa=fx
2.Secant
- Input iterasi,x1,x2
- Ulangi z sampai iterasi yang ditentukan
- Hitung nilai hasil1,hasil2,x3,hasil3,x1,x2
- Output, x1,x2,x3,hasil 1, hasil2, dan hasil3
28
-Flowchart:
Start
fungsi:=(o*o*o)
+(4*o*o)-10;
end;
var pil,i,n,z,r:integer;
a,b,x,fa,fb,fx,hasil1,hasil2,hasil3,x1,x
2,x3:real;
label back,akhir;
Input pilihan
perhitungan
Biseksi no Secant
yes yes
While i<n
yes
for z :=
x:=(a+b)/2; 1 to r
fx:=fungsi(x);
a:=x; hasil1:=fungsi(x1);
((fx*fa)<0) no hasil2:=fungsi(x2);
fa:=fx;
x3:=hasil2*(x2-x1);
yes
x3:=x3/(hasil2-hasil1);
no
x3:=x2-x3; hasil3:=fungsi(x3);
yes
b:=x;
fb:=fx; Output
i,x1,x2,xt,fx1,f
x2,fxt
no
Output
I,a,x,b,fa,f
b,fx
End.
29
-Script
program BETA_CANTIK;
uses crt,math;
function fungsi(o:real):real;
begin
fungsi:=(o*o*o)+(4*o*o)-10;
end;
var pil,i,n,z,r:integer;
a,b,x,fa,fb,fx,hasil1,hasil2,hasil3,x1,x2,x3:real;
label back,akhir;
begin
clrscr;
writeln('pilih dulu mau ngitung apaan nih?');
write('pilihh= '); readln(pil);
if pil=1 then
begin
i:=1;
a:=1;
b:=2;
n:=10;
i:=1;
fa:=fungsi(a);
fb:=fungsi(b);
while i<=n do
begin
x:=(a+b)/2;
fx:=fungsi(x);
writeln(i,' ',a:0:2,' ',x:0:2,' ',b:0:2,' ',fa:0:2,' ',fx:0:2,' ',fb:0:2);
if ((fx*fa)<0) then
begin
b:=x;
30
fb:=fx;
end
else
begin
a:=x;
fa:=fx;
end;
i:=i+1;
end;
end;
if pil=2 then
begin
z:=1;
back:
write('masukkan banyaknya iterasi = ');readln(r);
write('masukkan nilai x1 = ');readln(x1);
write('masukkan nilai x2 = ');readln(x2);
writeln;
writeln;
writeln(' x1 x2 x* f(x1) f(x2) f(x*)');
for z := 1 to r do
BEGIN
hasil1:=fungsi(x1);
hasil2:=fungsi(x2);
x3:=hasil2*(x2-x1);
x3:=x3/(hasil2-hasil1);
x3:=x2-x3;
hasil3:=fungsi(x3);
writeln(x1:0:4,x2:10:4,x3:11:4,hasil1:12:4,hasil2:12:4,hasil3:12:4);
x1:=x2;
x2:=x3;
31
END;
akhir:
readln;
end;
end.
32
-Hasil Run:
Metode biseksi
Metode secant
33
3. –Flowchart:
start
Output
Bisection, linear
interpolation
Input
Choice?
If
no if ch==2
Ch==1
yes yes
Output
Output
Bisection
Linear interpolation
method
Input
Input
Eq,x1,x2
Eq,x1,x2
Output Output
T, -rA T, -rA
yes yes
no no
yes yes
x1=x3;
x1=x3;
eqx1=eqx3;
eqx1=eqx3; no
x3=(x1+x2)/2; x3=x2-(eqx2*(x2-x1))/(eqx2-eqx1);
eqx3=subs(eq,x,x3); eqx3=subs(eq,x,x3);
End.
34
-Script:
clear all
clc;
syms x;
disp('1. bisection');
disp('2. linear interpolation');
disp('equation: -rA= 2.3*(PA^2) +3*PA - 11 ');
ch=input('choice = ');
if ch==1
disp('Bisection Method');
eq=input('Input the Equation=');
x1=input('input the first x(x1)=');
x2=input('input the second x(x2)=');
eqx1=subs(eq,x,x1);
eqx2=subs(eq,x,x2);
x3=(x1+x2)/2;
eqx3=subs(eq,x,x3);
tol=0.02;
disp('======================');
disp(' T -rA ');
disp('======================');
fprintf('%7.3f%12.3f\n',x3,eqx3)
while abs(eqx3)>tol;
if (eqx1*eqx3)<0;
x1=x3;
eqx1=eqx3;
else
x1=x2;
eqx1=eqx2;
x2=x3;
eqx2=eqx3;
35
end;
x3=(x1+x2)/2;
eqx3=subs(eq,x,x3);
fprintf('%7.3f%12.3f\n',x3,eqx3)
end
disp('======================');
end
if ch==2
disp('LINEAR INTERPOLATION');
eq=input('equation please? ');
x1=input('input the first x(x1)=');
x2=input('input the second x(x2)=');
eqx1=subs(eq,x,x1);
eqx2=subs(eq,x,x2);
x3=x2-(eqx2*(x2-x1))/(eqx2-eqx1);
eqx3=subs(eq,x,x3);
tol=0.01;
disp('======================');
disp(' T -rA ');
disp('======================');
fprintf('%7.3f%12.3f\n',x3,eqx3)
while abs(eqx3)>tol;
if (eqx1*eqx3)<0;
eqx1=eqx3;
x1=x3;
else
x1=x2;
eqx1=eqx2;
x2=x3;
eqx2=eqx3;
end;
36
x3=x2-(eqx2*(x2-x1))/(eqx2-eqx1);
eqx3=subs(eq,x,x3);
fprintf('%7.3f%12.3f\n',x3,eqx3)
end
disp('======================');
end
37
-Hasil Run:
38
4.a,b,c
4a. –Flowchart
start
Output
Soal 4a
p2=3; u1=100;
u3=600; deltav1=50;
ws=240; deltav=ws/p2;
Output
U, P, Ws,
Q
While
u1<600
no yes
Q=((u1^2)*(10^(-3))/2)-ws;
u1=u1+deltav1;
End.
- Script
39
clear all;
clc;
disp('soal 4a');
p2=3;
u1=100;
u3=600;
deltav1=50;
ws=240;
deltav=ws/p2;
fprintf('%8s%8s%8s%10s\n','U (m/s)','P(bar)','Ws(kJ)','Q(kJ/kg)');
while u1<600;
Q=((u1^2)*(10^(-3))/2)-ws;
fprintf('%3.0f%10.3f%10.3f%10.3f\n',u1,p2,ws,Q);
u1=u1+deltav1;
end
40
- Hasil run:
41
4b. –Algoritma:
a. Memulai program.
b. Menampilkan data yang diketahui berupa Kp dan P
c. Menginputkan nilai X1, X2 pada awal program.
d. Memproses fungsi X1 dan X2 pada persamaan.
e. Memproses pengulangan data dengan while untuk menampilkan data X3
dan F(X3) hingga batas tertentu.
f. Mengakhiri program.
42
-Flowchart:
START
Input
X1, x2
f=inline('((3*x)^0.5)-(x*(3+x)^0.5)-
(6.12*(x+1)^0.5)'); i=1;
while abs
F(x2)>tol
yes
x3=x2-f(x2)*(x2-x1)/
no (f(x2)-f(x1));
X1=x2; X2=x3
END
43
-Script:
clear all;
clc;
toleransi=0.01
disp(' Program Laporan Resmi II');
disp(' Metode Secant');
disp('Diketahui :');
disp('Kp : 3.06');
disp('P : 5 atm');
disp(' ');
disp('Ditanya :');
disp('Nilai x ?');
disp(' ');
disp('Jawab:');
disp(' ');
disp('--------------------------');
x1=input('Masukkan nilai X1=');
x2=input('Masukkan nilai X2=');
f=inline('((3*x)^0.5)-(x*(3+x)^0.5)-(6.12*(x+1)^0.5)');
i=1;
disp('i xi-1 xi xi+1 f(xi-1) f(xi) f(xi+1)');
disp('--------------------------------------------------------------------');
while abs(f(x2))>toleransi
x3=x2-f(x2)*(x2-x1)/(f(x2)-f(x1));
disp(sprintf('%3.0f%10.2f%10.2f%10.2f%10.2f%9.2f%9.2f\n',i,x1,x2,x3,f(x1)
,f(x2),f(x3)));
x1=x2;
x2=x3;
i=i+1;
end
44
-Hasil run:
45
c. Menghitung konsentrasi dengan metode biseksi
- Script:
clear all;
clc;
syms ca;
%determining the concentration in steady state, using bisection
disp('Know: Constant Volume; F/v: 1/minute; CAF=1 gmol/L; und K=1
L/gmol.min');
eq=input('input the equation for this problem=');
cona1=input('Enter Lower value of A concentration (Ca1) = ');
cona2=input('Enter Higher value of A concentration(Ca2) = ');
tol=input('Toleration = ');
fcona1=subs(eq,ca,cona1);
fcona2=subs(eq,ca,cona2);
c=(cona1+cona2)/2;
fc=subs(eq,ca,c);
if (fcona1*fcona2)>0;
cona1=input('Another value of A concentration (lower)(Ca1) = ');
cona2=input('Another value of A concentration (higher)(Ca2) = ');
fcona1=subs(eq,ca,cona1);
fcona2=subs(eq,ca,cona2);
else
c=(cona1+cona2)/2;
fc=subs(eq,ca,c);
end
disp('================================================');
disp(' CA1 CA2 C fCA1 fCA2 fC ');
disp('===============================================');
i=1;
fprintf('%6.2f%11.2f%11.2f%11.2f%11.2f%10.2f\n',cona1,cona2,c,fcona1,
fcona2,fc);
46
while abs(fc)>tol;
i=i+1;
if (fcona1*fc)<0;
cona2=c;
fcona2=fc;
else
cona1=c;
fcona1=fc;
end
c=(cona1+cona2)/2;
fprintf('%6.2f%11.2f%11.2f%11.2f%11.2f%10.2f\n',cona1,cona2,c,fcona1,
fcona2,fc);
fc=subs(eq,ca,c);
end
disp(' ');
disp(' done ');
47
-Hasil Run
48