0% found this document useful (0 votes)
61 views7 pages

Laboratory No. 1 Numerical Methods

The document describes using the bisection method to find the roots of non-linear equations. It provides the theory, algorithm, and procedures for implementing the bisection method in Octave software to approximate roots. Example functions are given to find roots both manually and using a sample bisection code script in Octave.

Uploaded by

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

Laboratory No. 1 Numerical Methods

The document describes using the bisection method to find the roots of non-linear equations. It provides the theory, algorithm, and procedures for implementing the bisection method in Octave software to approximate roots. Example functions are given to find roots both manually and using a sample bisection code script in Octave.

Uploaded by

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

Laboratory Activity no.

1 Iterative Bracketing Method (Bisection Method)

Objectives:
1. To determine roots of an equation using Bisection method.
2. To be able to apply the knowledge in Bisection Method using the
Octave Software;
3. To simulate the program and find the roots of a given function.
Materials

 Laptop/ Computer
 Octave Software

Theory:
Bisection Method: 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. It is
also called Interval halving, binary search method and dichotomy method. It
means if a function f(x) is continuous in the closed interval [a, b] and the f(a)
and f(b) are two real numbers of opposite signs that contain at least one
real root of f(x) = 0, between a and b. This method is also known as the
Bolzano or Half Interval or Binary search method.

Fig1. Bisection method graph


Bisection Method flowchart:
The bisection method approximates the roots of continuous functions by
repeatedly dividing.

Bisection Method Algorithm:


1. Decide initial values for x1 and x2 and stopping criterion E.
2. Compute f1 = f (x1) and f2 = f (x2).
3. If f1 * f2> 0, x1 and x2 do not bracket any root and go to step 1.
4. Compute x0 = (x1 + x2) / 2 and compute f0 = f (x0).
5. If f0 = 0 then x0 is the root of the equation, print the root
6. If f1 * f0< 0 then set x2 = x0 else set x1 = x0.
7. If |(x2-x1) |<= E then root = (x1 + x2) / 2, print the root and go to step 8
Else go to step 4
8. Stop.

Procedures:
Before you can create the code or program, you must install Octave on your
device. However, there are alternatives available if your laptop or personal
computer meets the high specifications required for software like Matlab,
which is good for program simulations. If not, stick to Octave or Octave
online.
This method assumes that the program was preinstalled on your device, and
the processes and illustrations may differ from the alternatives indicated
above at some point.
1. Search and open the Octave software on your device.
2. Go to editor and create a new script.

3.Type the sample code for Bisection Method in the opened script and saved
as Bisection.
function bisection_method()
f = @(x) x^2 - 9;
eps = 1e-6;
a = 0; b = 1000;
[solution, no_iterations] = bisection(f, a, b, eps);
if solution <= b % Solution found
fprintf('Number of function calls: %d\n', 1+2*no_iterations);
fprintf('A solution is: %f\n', solution);
else
fprintf('Abort execution.\n');
end
end

function [result1, result2] = bisection(f, x_L, x_R, eps)


if f(x_L)*f(x_R) > 0
fprintf('Error! Function does not have opposite\n');
fprintf('signs at interval endpoints!')
exit(1)
end
x_M = (x_L + x_R)/2.0;
f_M = f(x_M);
iteration_counter = 1;
while abs(f_M) > eps
left_f = f(x_L);
right_f = f(x_R);
if left_f*f_M > 0 % i.e., same sign
x_L = x_M;
else
x_R = x_M;
end
x_M = (x_L + x_R)/2;
f_M = f(x_M);
iteration_counter = iteration_counter + 2;
end
result1 = x_M;
result2 = iteration_counter;
end
4. After typing the script, go to command window and type Bisection.
5. The root is showed in the command window.
EXERCISES:
1. Find the root of the given function. (Manual computation):
a. x2 – 9
b. x3 +4x2 – 10
c. x2 + 2x – 8
d. x2 + 3x – 5
e. x3 -x - 1

2. After finding the roots of the given function, screenshot the algorithm and
the outputs.

You might also like