Lab Report Numerical Method
Lab Report Numerical Method
OBJECTIVES :
To determine roots of an equation in single variable using Bisection method.
To understand the MATLAB code implementation of the Bisection method.
THEORY :
The bisection method is a simple and convergence method used to get the real roots of non-linear
equations. The Bisection method repeatedly bisects or separates the interval and selects a
subinterval in which the root of the given equation is found. It is a very simple and robust method but
slower than other methods. Bisection Method calculates the root by first calculating the midpoint of
the given interval end Points.
ALGORITHM :
1. Start.
2. Define function f (x).
3. Choose initial guesses xo and x1 such that f(x)f(x) < 0.
4. Choose pre-specified tolerable error e.
5. Calculate new approximated root as x2 = (x+x₁) 2.
6. Calculate f(x)f(x2).
7. If f(x)f(x2) < 0 then xo xo and X1 = X2.
8. If f(x)f(x2) > 0 then xo = x2 and X1 = X1.
9. If f(x)f(x2) = (0) then goto (8).
10. If f(x2)> e then goto (5) otherwise goto (8).
11. Display x2 as root.
12. Stop.
PROGRAM :
% Function definition
y = f(x);
figure;
xlabel('x');
ylabel('f(x)');
hold on;
% Bisection method to find the root
b = 1;
tol = 1e-6; % Tolerance for convergence
fb = f(b);
if fa * fb > error('The function does not change sign in the interval [a, b]');
end
fc = f(c);
if abs(fc) < tol
break;
end
if fa * fc < 0
b = c;
fb = fc;
else
a = c;
fa = fc;
end
if iter == max_iter
warning('Maximum number of iterations reached. The result may not be accurate.');
end
fprintf('Number of iterations: %d\n', iter);
OUTPUT :
DISCUSSION :
From this practical, it can be concluded that the bisection method is an iteration method with faster rate
of getting roots of equation and we found out it 0.517757.