Bisection Method: Laboratory Activity No. 4
Bisection Method: Laboratory Activity No. 4
Bisection Method: Laboratory Activity No. 4
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:
Procedure:
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.
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.
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?
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.
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
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.
.
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).
CONCLUSION
After this experiment, we are able to define and learn on what are
the different classifications of the while and for loops.
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
13 | P a g e