You are on page 1of 4

Department of Materials Science & Engineering

Chittagong University of Engineering & Technology

Name: Kashfi Uddin


ID: 1912019
Course code: MATH 316
Course Title: Numerical Methods in Engineering Sessional

Experiment no.: 01
Experiment name: Determination of the roots of an equation in a single
variable using the Bisection method
Objectives:
1. To determine the roots of an equation in a single variable using the Bisection method.
2. To understand the MATLAB implementation of the Bisection method.
3. To analyze results using different initial values and error tolerance.

Introduction:
In various science and engineering research fields, the solution of nonlinear equations is required to advance
the research purpose. The bisection method is a reliable and extensively used numerical approach for
locating nonlinear equation roots. It is based on the intermediate value theorem, which claims that if the
sign of a continuous function changes across an interval, it must have at least one root within that interval.
The bisection method begins with an initial interval and bisects it repeatedly, narrowing the search range
until the desired level of accuracy is achieved. This approach is relatively easy to implement and assures
solution convergence if specific requirements are met.

Bisection Method:
It is also called binary chopping or the half-interval method. For resolving f(x) = 0, the bisection method
is one of the easy and most valid iterative procedures. It is based on intermediate value property, i.e.
whether f(x) is real and continuous in (a, b) and f(a), f(b) are opposed signs, then ∃ at least one root in (a,
b) such that

x0 = a + b
2

Now the following three cases arise

• If f(x0) = 0, then is x0 root of f(x).


• If f(x0) > 0, then root of f(x0) will lie between x0 and a , that is
a + x0
X1=
2
• If f(x0) < 0, then root will lie between x0 and b , that is

b + x0
X2=
2
Figure 1 : A few steps of the bisection method applied over
the starting range [a1;b1].

Algorithm:
1. Step 1: Define the nonlinear equation. The first step is to define the provided nonlinear equation as
a function; we'll name it "f(x)".
2. Step 2: Choose an interval. Choose a starting interval [a, b] such that the signs of f(a) and f(b) are
the opposite. This guarantees that a root is present during the interval.
3. Step 3: Set convergence criteria: The appropriate tolerance, epsilon, denotes the permitted
inaccuracy in the root approximation.
4. Step 4: Implement the bisection method:
• Initialize variables: Set a counter, n, to 0.
• While (b - a) > epsilon, do the following steps:
• Increment the counter: n = n + 1.
• Calculate the midpoint: c = (a + b) / 2.
• Evaluate f(c): Compute f(c) using the defined function.
• Check for convergence: If f(c) is within the appropriate tolerance or equal to zero, the
iteration should be terminated.
• Update the interval: Set b = c if the signs of f(a) and f(c) are the opposites; else, set a = c.
• Return the approximate root: Return the value of c to the nonlinear equation's approximate
root upon convergence.
Matlab Code:
%ingradients
f = input('Enter your function= ');
a = input('Enter left side of integer= ');
b = input('Enter right side of integer= ');
n = input('Enter no of iterations= ')
e = input('Enter tolerance= ')
if f(a)*f(b)<0
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;
else if f(b)*f(c)<0
a=c;
end
end
end

Result:
After inputting the code into Matlab and running without any error, we define the function,
F(x)= x^3-x^2-11;
The root is 2.6121

Discussion:
This lab report presented an implementation of MATLAB's bisection method to solve nonlinear
equations. The results showed that the bisection method converged to a root within a specified tolerance
(up to 4 decimals). The calculation is so time efficient in Matlab than hand calculation.

You might also like