You are on page 1of 7

Jawaban Modul Praktikum 1

NIM : 102316054

Nama : Ardwikha Septa Mahendra

Kelas : CE-2

M-script No.1

x = (-0.5:0.001:0.5)
Pt = 3
K = 0.05
K = x./(1-x).*sqrt(2.*Pt./(2+x))
plot(x,K)
title('Plot K vs x')
xlabel('Fraksi Mol terdisosiasi')
ylabel('Konstanta keseimbangan reaksi')
grid

Plot No.1
M-script No.2

function r = bisect(f, a, b, kmax, tol)


f = @(x)(x./(1-x).*sqrt (6./(2+x)))-0.05;
a = -0.5;
b = 0.5;
if nargin < 5, tol = 1e-8; end
if nargin < 4, kmax = 30; end

eror = 100;
ea = 0;% Pre-allocate
if f(a)*f(b) > 0
r = 'failure';
return
end
disp('==================================================================='
)
disp('iteration xl xu xr ea er(%)')
disp('-------------------------------------------------------------------'
)
for k = 1:kmax,
c(k) = (a+b)/2;
fprintf('%3i %11.6f%11.6f%11.6f%14.6f%14.6f\n',k,a,b,c(k),ea,eror)
if f(b)*f(c(k)) < 0 % Check sign changes
a = c(k);
else b = c(k);
end
c(k+1) = (a+b)/2; % Find the next c
eror = abs(c(k+1)-c(k))/c(k+1);
ea = abs(c(k+1)-c(k));
if eror < tol, % Stop if tolerance is met
r = c(k+1);
break
end
end
disp('==================================================================='
)
Output No.2
M-script No.3

function r = Secant(f, x0, x1, N, tol)


f = @(x)(x/(1-x))*sqrt(6./(2+x))-0.05;
x0 = 0.8;
x1 = 0.5;
if nargin < 5, tol = 1e-8;end
if nargin < 4, N=20 ;end
x = zeros(1, N+1);
x(1) = x0;
x(2) = x1;
disp('==============================================================')
disp(' i x(i-1) x(i) x(i+1) f(x(i+1)) er')
disp('--------------------------------------------------------------')
for i = 1:N
x(i+2) = x(i+1)-(f(x(i+1))*(x(i)-x(i+1)))/(f(x(i))-f(x(i+1)));
eror = abs(x(i+2)-x(i+1))/x(i+2);
fprintf('%3i %11.6f%11.6f%11.6f%11.6f%11.2e\n',i,x(i),x(i+1),x(i+2),
f(x(i+2)),eror*100)
if eror < tol
r = [x(i+2) ];

break

end

Output No.3
M-script No.4

f = @(x)(x./(1-x).*sqrt (6./(2+x)))-0.05 ;
x0= 0.5;
options = optimset ('display','iter','tolX',0.1);
r= fzero(f,x0,options)
Output No.4

% Isilah nilai-nilai pada table berikut:

TolXx0.10.060.010.024110-80.282

You might also like