Bisection Method: Activity No. 2

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Activity No.

Bisection Method

Introduction
Given a function f(x) = 0, the value of x that satisfies this equation is called the root of the function f(x). The method of finding the roots using numerical analysis is called root finding methods or root finding algorithms. There are a few root finding algorithms and one of the simplest is called the bisection method which repeatedly bisects an interval in which the root must lie. Although, the method is slower compared to other root finding algorithms, a study on this method would be necessary before we go to the other algorithms. The bisection method, which is alternatively called binary chopping, interval halving or Bolzanos method is one type of incremental search method in which the interval is always divided in half. If a function changes sign over an interval, the function value at the midpoint is evaluated. The location of the root is then determined as lying at the midpoint of the subinterval within which the sign change occurs. The process is repeated to obtain refined estimates.

I.

Objectives

At the end of this activity, the students are expected to: a. Manually perform calculation of the root of a function using Bisection Method. b. Make an Octave code to calculate the root of a function using Bisection Method using a fixed number of iterations. c. Implement Bisection Method using a termination criteria.

II.

Methodology
1. Given the function below, test whether the interval specified can be used to determine the root of the function by substituting them to the function. ( ) Solve for the root within the interval 0 and 1.

What is f(0) ?

__________________________________

What is f(1) ?

___________________________________

Can we expect a root of the function to lie between 0 and 1?

___________________________________

2. Manually perform calculation of the root of the given function in number 1 and the interval specified using Bisection Method. Limit to 5 digits at the right of the decimal point. Record your calculations in Table 2.1.

Table 2.1. Manual Calculation using Bisection Method. n 0 1 2 3 4 5 6 an 0 bn 1 cn f(cn)

Make observations on the values of f(cn) and write it here: _______________________________________________________ _______________________________________________________ _______________________________________________________

3. Open Octave and write a function m-file that provides the function in number 1. Save the function m-file as f.m. Manually calculate f(x) using your calculator and record it in column 2 of Table 2.2. Make several calls to the function m-file using Octave and verify it by comparing the results with the manually calculated f(x).

Table 2.2. Verifying f.m x -2 2 3 4 Manually Calculated f(x) Using f.m

4. Write a script m-file to perform root finding using Bisection Method. Save this script as bisection.m. The code must be able to continually test whether substituting the a and b will produce opposite signs. Make sure also that it outputs the values for each iteration. Using the script m-file calculate the root of the function in number one by using the f.m function you made in number 3. Record your observations in Table 2.3. Table 2.3. Output of bisection.m N 0 1 2 3 4 5 6 7 8 9 10 11 an 0 bn 1 cn f(cn)

What are your observations? _______________________________________________________ _______________________________________________________ _______________________________________________________

5. Rewrite the script m-file that performs the Bisection Method this time having a termination criteria. Code it such that when you substitute the calculated root to the function, the result will be observed and then terminated when it falls below the termination criteria. Save this script as bisection1.m. Make sure that it outputs the values for each iteration and it would be possible to count how many iterations were done. Using the script m-file calculate the root of the function: f(x) = x sin(x) - 1 Use and a termination value of 0.0001.

6. Make observations on how many iterations were performed

How many iterations did it take to perform the operation? __________________________________________ 7. Redo Step 5 and 6 this time have the tolerance value at 0.000001. What do you observe? _____________________________________

You might also like