0% found this document useful (0 votes)
56 views13 pages

Bisection Method: Laboratory Activity No. 4

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 13

BISECTION METHOD

Laboratory Activity No. 4

Bisection method is a numerical technique of finding the roots of a


function, say f(x), by repeatedly bisecting an interval and then selecting a
subinterval in which root lies for further processing. It starts by guessing
two values of x representing an interval in which the function produces a
positive and negative values.

Algorithm:

1. Select two values of x, say xl and xu, such that the function
changes signs. This can be verified by checking if 𝑓(𝑥𝑙) ∗
𝑓(𝑥𝑢) < 0.
2. Compute the approximate root by finding the midpoint of the
interval xl to xu.
𝑥𝑙 + 𝑥𝑢
𝑥𝑟 =
2
3. Determine the next interval by checking the following:
• If 𝑓(𝑥𝑙) ∗ 𝑓(𝑥𝑟) < 0, then the root lies between xl and xr.
Set a new value for xu which is the value of xr (𝑥𝑢 = 𝑥𝑟).
Return to step 2.
• If 𝑓(𝑥𝑙) ∗ 𝑓(𝑥𝑟) > 0, then the root lies between xr and xu.
Set a new value for xl which is the value of xr (𝑥𝑙 = 𝑥𝑟).
Return to step 2.
• If 𝑓(𝑥𝑙) ∗ 𝑓(𝑥𝑟) = 0, then the root is equal to xr. Then
terminate the computation.
4. If the relative approximate error is less than the prespecified
percent tolerance (𝜀𝑎 < 𝜀𝑠 ), then set the root equal to xr; else
return to step 2.

In this activity, a labVIEW code is used to implement the algorithm for the
bisection method in order to find the roots of 𝑓(𝑥) = 5𝑠𝑖𝑛2𝑥 + 5𝑐𝑜𝑠2𝑥 +
2𝑥. The bisection method will be more effective by having the graph of
the function f(x).

1|Page
Objective:

• To be able to build and modify labVIEW VI for bisection method.


• To be able to apply the algorithm for the bisection method in
finding the roots of an equation.

Procedure:

Creating a VI for the bisection method.

1. Open the labVIEW software.


2. Open a new VI by clicking on Blank VI in the LabVIEW Getting Started
window.
3. Save the VI as Bisection Method.vi.
4. Create the front panel and the block diagram as shown in Figure 1 and
2 respectively.

Figure 1

2|Page
Figure 2

3|Page
Figure 3a Enlarge View of the block diagram

4|Page
Figure 3b Enlarge View of the block diagram

5|Page
Notice that in the block diagram a case structure is part of the codes.
A Case Structure is a branching control mechanism that allows different
executions depending on the value of the selector label. To create a
Case Structure, right click on the block diagram, open the Functions
palette and open the Structures palette. Under Structures select the
Case Structure. Once you have selected the Case Structure in the
palette, your cursor will change to a box with a question mark in it. Click
and drag a box of a size suitable for the functions that is going to place in
the case structure and you will get a Case Structure as shown in Figure
4.

Figure 4

On the left side of the Case Structure, there is an input called a case
selector. It accepts a value to determine which case is to execute.
Considering the code in Figure 2, the Boolean values came from the
evaluation of comparing the result of 𝑓𝑥𝑙 ∗ 𝑓𝑥𝑢 if it is less than zero is the
input going to case selector. If 𝑓𝑥𝑙 ∗ 𝑓𝑥𝑢 < 0, the VI will proceed to case
structure of true value having codes to find the root by means of
bisection method. Otherwise the VI will proceed to structure with false

6|Page
value which has a code which simply displays the message of “Invalid xl
and xu. Input another values.”

5. Run the VI and verify its operation. The graph of f(x) will help you in
validating the operation of VI and determining all the roots of f(x).

20
15
10
5
0 Series1
-6 -4 -2 -5 0 2 4 6
-10
-15
-20
Figure 5 Graph of f(x)

6. Set the value of xli = 1 and xlu = 4. Then, run the VI. Observe the
resulting message display.

What is the message displayed in the front pannel? Is It consistent with


the graph of f(x)?

After setting the value of the xli = 1 and xlu = 4,


running the VI gave us an output message of invalid
xl and xu. Input other values. No it isn’t consistent.

7|Page
7. Determine all the roots of f(x) by assigning appropriately the value of
xli and xui based on the graph of f(x). Set the value of 𝜀𝑠 = 1%. Run the
VI. Record all the computed roots in the space below.

For this part, I assigned 4 for the xli and


2 for the xlu. After running the vi, I have
an output message of solution exists.

8. Verify the results of the last computation of the relative error for the
roots between -4 and -2.5 by manual calculation when 𝜀𝑠 = 5%. Use
the equation:
𝑥𝑟 𝑛𝑒𝑤 − 𝑥𝑟 𝑜𝑙𝑑
𝜀𝑎 = 𝑥100%
𝑥𝑟 𝑛𝑒𝑤

9. Modify the VI so that the value of f(xl) and f(xr) are displayed in the
array shown at the front panel.

What is the last value of f(xl) and f(xr) after running the VI?

After running the VI, we have observed for the


last remaining value of f(xl) and f(xr) are, -13.6473
and 1.2193

Name: _Josef Geminiano Instructor’s Initial: _____________


Student Number: _20151144193_ Date performed: _11-18-2020_

8|Page
Problem:

1. Modify the VI for testing the condition 𝑓𝑥𝑙 ∗ 𝑓𝑥𝑢 < 0 without using a
mathscript node.

2. Modify the VI such that numeric values of 1 and 0 are used as the
inputs for the case selector. 1 means valid xl and xu while 0 means
invalid xl and xu. A select function must be used for this purpose.

Figure 6 Select Function

9|Page
3. Create a new VI that will perform the calculation of finding the roots of
𝑓(𝑥) = 𝑥 3 + 𝑐𝑜𝑠3𝑥 by means of Bisection Method. The graph of f(x) will
help as a guide in finding all the roots of f(x). If the inputs for xl and xu
are invalid values, the VI will display “Invalid values for xl and xu. Input
another values.”. The VI will not terminate but instead, it will continue
running and accepting again new values for xl and xu. Once valid values
of xl and xu are detected, the VI will find the root and terminate according
to the required setting of tolerance.

f(x)=x^3+cos3x
10
8
6
4
2
0
-3 -2 -1 0 1 2 3
-2
-4
-6
-8

Figure 7 Graph of 𝑓(𝑥) = 𝑥 3 + 𝑐𝑜𝑠3𝑥

Write down all the roots of 𝒇(𝒙) = 𝒙𝟑 + 𝒄𝒐𝒔𝟑𝒙 at 𝜺𝒔 = 𝟏% on the space


provided.

10 | P a g e
Note: Using an extra sheet of bond paper, print your VI, the front panel
and the block diagram for problem 1, 2, and 3. Insert it inside your lab
report.
.

SUMMARY OF LEARNING OUTCOMES:

From our last experiment, we familiarized ourselves on the


functions of the while and for loop. On this experiment, our goal is
to create a VI that has an operation of a BISECTION METHOD.

In mathematics, the bisection method is a root-finding method


that applies to any continuous functions for which one knows two
values with opposite signs. The method consists of repeatedly
bisecting the interval defined by these values and then selecting
the subinterval in which the function changes sign, and therefore
must contain a root. It is a very simple and robust method, but it
is also relatively slow. Because of this, it is often used to obtain a
rough approximation to a solution which is then used as a starting
point for more rapidly converging methods. The method is also
called the interval halving method, the binary search method, or
the dichotomy method.

11 | P a g e
The method is applicable for numerically solving the equation f(x)
= 0 for the real variable x, where f is a continuous function defined
on an interval [a, b] and where f(a) and f(b) have opposite signs. In
this case a and b are said to bracket a root since, by the
intermediate value theorem, the continuous function f must have
at least one root in the interval (a, b).

At each step the method divides the interval in two by computing


the midpoint c = (a+b) / 2 of the interval and the value of the
function f(c) at that point. Unless c is itself a root (which is very
unlikely, but possible) there are now only two possibilities: either
f(a) and f(c) have opposite signs and bracket a root, or f(c) and f(b)
have opposite signs and bracket a root.[5] The method selects the
subinterval that is guaranteed to be a bracket as the new interval
to be used in the next step. In this way an interval that contains a
zero of f is reduced in width by 50% at each step. The process is
continued until the interval is sufficiently small.

CONCLUSION

After this experiment, we are able to define and learn on what are
the different classifications of the while and for loops.

Also we are able to familiarize ourselves with the different


functions of the NI labview. I also learned on how to generate the
loop for the excercises given. Specifically, the while loop, case
structure, and the mathscript.

12 | P a g e
I also learned, that on the bisection method, when value a isn’t
higher than value b, there’s a possibility that the results would be
invalid.

I also learned, when you input a VALID output, you should first
stop the loop, because if you don’t the functions are still on
continuous loop, and the values won’t change. The values are still
invalid.

REFERENCES:

Bisection method
https://en.wikipedia.org/wiki/Bisection_method

Rules of bisection method


http://www.sosmath.com/calculus/limcon/limcon07/limc
on07.html

13 | P a g e

You might also like