Beruflich Dokumente
Kultur Dokumente
START
INPUT TERM
F(x), xL, XU, ES
SET F(X)=0.
REPLACE XL TO
THE TERM F(X) TO
A
GET F(XL) AND XU
TO GET F(XU)
NO
B STOP
YES
SET XL=XL, [F(XL)][F(XM)]<0?
A XU=XM
NO
YES
SET XL=XM,
A [F(XL)][F(XM)]>0?
XU=XU
NO
YES
B DISPLAY [F(XL)][F(XM)]=0?
XM
CODE:
function XM = bisection(F, XL, XU, ES)
disp('Bisection Method');
F = input('Enter a function [@(x) 3*x^4-5;]: ');
XL = input('Enter XL: ');
XU = input('Enter XU: ');
ES = input('Enter ES: ');
% Work with the limits modifying them until you find a function close
enough to zero.
disp('Iter XL XU XM');
while (abs(XU - XL) >= ES)
i = i + 1;
% Find a new value to be tested as a root
XM = (XU + XL)/2;
y3 = feval(F, XM);
if y3 == 0
fprintf('Root at x = %f \n\n', XM);
return
end
fprintf('%2i \t %f \t %f \t %f \n', i-1, XL, XU, XM);
Exercise 4 Laboratory
Bisection Method
NumMeth
April 17, 2017