NM-Lab 08 Bisection Method Lab
NM-Lab 08 Bisection Method Lab
Find two points, say a and b such that a < b and f(a)* f(b) < 0
t is the root of the given function if f(t) = 0; else follow the next step
Divide the interval [a, b] – If f(t)*f(a) <0, there exist a root between t and a
– else if f(t) *f (b) < 0, there exist a root between t and b
The bisection method is an approximation method to find the roots of the given equation by repeatedly
dividing the interval. This method will divide the interval until the resulting interval is found, which is
extremely small.
You must have a function f(x)f(x) defined either as an inline function or as a separate function file.
Example:
Make sure:
f(a)*f(b) < 0
a = 1; % Start of interval
b = 2; % End of interval
if f(a)*f(b) > 0
end
for i= 1:n
c= (a+b)/2
fprintf('P%d=%.4f\n',i,c)
if abs(c-b)<e || abs(c-a)<e
break
end
if f(a)*f(c)<0
b=c;
elseif f(b)*f(c)<0
a=c;
end
end
end