0% found this document useful (0 votes)
18 views4 pages

Lab Report Numerical Method

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views4 pages

Lab Report Numerical Method

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

 NAME OF EXPERIMENT:

To find the roots of Non-linear equation using Bisection 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

f = @(x) cos(x) - x .* exp(x);

% Plot the function


x = linspace(-5, 2, 1000); % Adjust the range as needed

y = f(x);
figure;

Numerical Method Lab Report-02, Page 1 of 4


plot(x, y);

xlabel('x');
ylabel('f(x)');

title('Plot of f(x) = cos(x) - x * e^x');


grid on;

hold on;
% Bisection method to find the root

a = -1; % Initial interval [a, b]

b = 1;
tol = 1e-6; % Tolerance for convergence

max_iter = 100; % Maximum number of iterations


fa = f(a);

fb = f(b);

if fa * fb > error('The function does not change sign in the interval [a, b]');
end

for iter = 1:max_iter


c = (a + b) / 2;

fc = f(c);
if abs(fc) < tol

fprintf('Root found at x = %f\n', c);

break;
end

if fa * fc < 0
b = c;

fb = fc;

else
a = c;

fa = fc;
end

Numerical Method Lab Report-02, Page 2 of 4


% Plot the current interval

plot([a b], [f(a) f(b)], 'ro-');


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);

fprintf('Estimated root: %f\n', c);

 OUTPUT :

Root found at x = 0.517757


Number of iterations: 19
Estimated root: 0.517757

 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.

Numerical Method Lab Report-02, Page 3 of 4


Numerical Method Lab Report-02, Page 4 of 4

You might also like