MATLAB: Boling point problem with bisection method

boiling pointhomework

Hi everybody! im trying to solve a boiling problem with bisection method. but there is something wrong.
Question is:
To solve it, i wrote these codes: but there is an error (too many input arguments)
function bisection(a, b, eps)
iter=0;
global k A B C
k=[0.05 0.15 0.5 0.3];
A=[15.8333 15.8366 15.8737 15.9426];
B=[2477.07 2697.55 2911.32 3120.29];
C=[-39.94 -48.78 -56.51 -63.63];
xm = (a+b)/2;
x=[a b xm];
f = fonk(x);
for i=1:4
exp(A-B/(x+C))*k*133.32-1e5;
end
while abs(a-b)>eps
if f(1)*f(3) <=0
b = xm;
elseif f(2)*f(3)<=0
a = xm;
else
disp('You have a ill conditioned function or multiple root');
end
iter=iter+1;
end
fprintf('Bulunan kök değeri (sürtünme katsayısı) = %8.5f \n', (a+b)/2);
fprintf('%i. iterasyonda sonuca ulaşıldı. \n', iter);
end
function [f] = fonk(x)
global k A B C
f=exp(A-B/(x+C))*k*133.32-1e5;
end

Best Answer

Try this code. Check the differences with your code to see the mistakes
x = bisection(300, 400, 0.001);
function xm = bisection(a, b, eps)
iter = 0;
global k A B C
k=[0.05 0.15 0.5 0.3];
A=[15.8333 15.8366 15.8737 15.9426];
B=[2477.07 2697.55 2911.32 3120.29];
C=[-39.94 -48.78 -56.51 -63.63];
while abs(a-b)>eps
xm = (a+b)/2;
if fonk(a)*fonk(xm) <=0
b = xm;
elseif fonk(xm)*fonk(b)<=0
a = xm;
else
disp('You have a ill conditioned function or multiple root');
end
iter=iter+1;
end
fprintf('Bulunan kök değeri (sürtünme katsayısı) = %8.5f \n', (a+b)/2);
fprintf('%i. iterasyonda sonuca ulaşıldı. \n', iter);
end
function [f] = fonk(x)
global k A B C
f=sum(exp(A-B./(x+C)).*k*133.32)-1e5;
end