Lab Report: Finding Real Roots of Non-Linear Equations
Using the Bisection Method in MATLAB
1. Title: To Find Real Roots of the Non-Linear Equation Using the Bisection Method
2. Objective
The objective of this lab is to find the real roots of a non-linear equation using the Bisection
Method in MATLAB. This method is iterative and helps in finding roots of continuous
functions that change signs over an interval.
3. Theory
Bisection Method
The Bisection Method is a bracketing method that repeatedly divides an interval in half and
selects the subinterval in which the root lies. It is based on the Intermediate Value Theorem,
which states that if a continuous function f(x)f changes sign over an interval [a,b], then there
exists at least one root in that interval.
Steps involved in the Bisection Method:
1. Initial Interval Selection: Choose an initial interval [a,b] such that f(a)⋅f(b)<0.
2. Midpoint Calculation: Calculate the midpoint c=a+b/2.
3. Root Determination: Evaluate f(c):
o If f(c)= 0, then c is the root.
o If f(a)⋅f(c)<0, then the root lies in [a, c].
o If f(b)⋅f(c)<0, then the root lies in [c, b].
4. Iteration: Repeat steps 2-3 until the interval is sufficiently small or the desired
accuracy is achieved.
4. Materials and Methods
Materials
MATLAB Software
Computer
Methods
1. Define the non-linear equation f(x) in MATLAB.
2. Choose the initial interval [a,b] such that f(a)⋅f(b)<0.
3. Implement the Bisection Method in MATLAB to find the root.
4. Set a tolerance level to determine the accuracy of the root.
5. Iterate the method until the interval size is less than the tolerance or the maximum
number of iterations is reached.
6. Display the root and the number of iterations taken to converge.
5. Procedure
1. Define the Function: Define the non-linear function f(x) for which the root is to be
found.
2. Initial Interval: Select the initial values of a and b.
3. Set Tolerance and Maximum Iterations: Define the tolerance level and the
maximum number of iterations.
4. MATLAB Code: Implement the Bisection Method in MATLAB.
[Link] Code:
We will use MATLAB codes for both defined and undefined equations.
clc Undefined equations
clear all
close all
f = input('Enter the function:');
a= input('Enter the value which the fucction in negative:');
b=input('Enter the value which the fucction in Positive:');
e= input('Enter tolarance:');
n= input('No of Iteration:');
if f(a)*f(b)<0
for i= 1:n
c=(a+b)/2;
fprintf('After Intretion %d:%0.6f\n',i,c);
if abs (c-a)<e||abs (c-b)<e
break;
end
if f(c)*f(a)<0
b=c;
elseif f(c)*f(a)>0
a=c;
end
end
else
disp('the Inerval you provided is not correct');
end
clc Defined equations
clear all
close all
f = function = @(x) x^3 - x + 4;
a= -1.8;
b=-1.7;
e= 0.000001;
n= 100;
if f(a)*f(b)<0
for i= 1:n
c=(a+b)/2;
fprintf('After Intretion %d:%0.6f\n',i,c);
if abs (c-a)<e||abs (c-b)<e
break;
end
if f(c)*f(a)<0
b=c;
elseif f(c)*f(a)>0
a=c;
end
end
else
disp('the Inerval you provided is not correct');
end
[Link]
1. Define the Function: The non-linear function f(x) = x3−x+4 is defined using an
anonymous function handle.
Initial Interval: The initial interval [a ,b] is chosen as [−3,−2] based on the visual inspection
of the function's plot. The function f(x) changes sign over this interval.
2. Tolerance Level and Maximum Iterations: A tolerance level of 10-6 and a
maximum number of iterations of 100 are set.
3. Bisection Method Implementation: The Bisection Method is applied iteratively to
find the root of the function within the specified tolerance.
4. Display the Result: The root and the number of iterations taken to converge are
displayed.
8. Results
After running the MATLAB code, the root of the non-linear equation x3 - x + 4 = 0 was
found. The results are as follows:
Root: -1.857864
Number of Iterations: 20
9. Discussion
The Bisection Method successfully narrowed down the interval to find the root of the non-
linear equation x3−x+4=0. The method converged to the root within the specified tolerance
after 20 iterations.
Key observations:
Initial Interval Selection: Choosing the correct initial interval [−3,−2] where the
function changes sign was crucial for the success of the method. This selection was
based on a visual inspection of the function's plot, ensuring that the root lies within
the interval.
Convergence: The method demonstrated stable convergence, progressively reducing
the interval size until the root was located within the desired tolerance level.
Robustness: The Bisection Method proved to be robust, as it guarantees convergence
as long as the initial interval is chosen correctly and the function is continuous within
that interval.
The result −1.857864 is a valid root for the equation x3−x+4=0, as verified by evaluating the
function at this point. The number of iterations (20) indicates that the method efficiently
narrowed down the root with the specified tolerance of 10-6.
10. Conclusion
The Bisection Method is a reliable and straightforward numerical technique for finding roots
of non-linear equations. By implementing the method in MATLAB, we successfully found
the real root of the equation x3−x+4=0. The process involved iterative halving of the interval
until the desired accuracy was achieved, demonstrating the effectiveness and robustness of
the Bisection Method in numerical root-finding.