Professional Documents
Culture Documents
NIM : 102316054
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
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
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
TolXx0.10.060.010.024110-80.282