Laboratory No. 1 Numerical Methods
Laboratory No. 1 Numerical Methods
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.
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
2. After finding the roots of the given function, screenshot the algorithm and
the outputs.