Laboratory 1
Laboratory 1
Numerical Methods
LAB SHEETS
STUDENT WORKBOOK
LAB EXPERIMENT # 1: ROOT FINDING USING BISECTION METHOD
Objectives
1. To determine roots of an equation in single variable using Bisection method.
Algorithm
𝑥𝑙 + 𝑥𝑢
𝑥𝑟 =
2
Step 3: Make the following evaluations to determine in which subinterval the root lies
(a) If 𝑓(𝑥𝑙 )𝑓(𝑥𝑢 ) < 0, the root lies in the lower subinterval. Therefore, set xu = 𝑥𝑟 and
return to step 2.
(b) If 𝑓(𝑥𝑙 )𝑓(𝑥𝑢 ) > 0, the root lies in the upper subinterval. Therefore, set 𝑥𝑙 = 𝑥𝑟 and return
to step 2.
𝑥𝑟𝑛𝑒𝑤 − 𝑥𝑟𝑜𝑙𝑑
𝜀𝑎 = | | 100%
𝑥𝑟𝑛𝑒𝑤
𝑥𝑟𝑛𝑒𝑤 𝑖𝑠 𝑡ℎ𝑒 𝑟𝑜𝑜𝑡 𝑜𝑓 𝑡ℎ𝑒 𝑐𝑢𝑟𝑟𝑒𝑛𝑡 𝑖𝑡𝑒𝑟𝑎𝑡𝑖𝑜𝑛 𝑎𝑛𝑑 𝑥𝑟𝑜𝑙𝑑 𝑖𝑠 𝑡ℎ𝑒 𝑟𝑜𝑜𝑡 𝑜𝑓 𝑡ℎ𝑒 𝑝𝑟𝑒𝑣𝑖𝑜𝑢𝑠 𝑖𝑡𝑒𝑟𝑎𝑡𝑖𝑜𝑛
Practical Work
Preliminary Work (to be done before lab session)
1. Consider the function 𝑓(𝑥)= cos(𝑥) − sin(3𝑥) = 0. Plot the graph of the function in the interval
[-4, 4].
2. Find a root of the function using the initial interval [0, 0.5]. Perform 5 iterations of the
Bisection method.
3. Understand the algorithm, the corresponding pseudo-code and Scilab code of the Bisection
method.
//display string
printf("Iteration \t Xr \t ea\n") ;
while (1) //this loop is ALWAYS true but will be stopped by the stopping criterion
//Bisection method
xr = (xl + xu) / 2;
//stopping criterion
//terminate the loop if solution is found or if maximum no. iteration is
reached
if (ea < es) | (iter >= imax)
break; //end loop
end
end
endfunction
function y=f(x)
//////////////////////////////////////////////////////////////////////////
// This function implements the equation f(x) = cos(x) - sin(3x)
//////////////////////////////////////////////////////////////////////////
// Input(s):
// x = input argument for the function
// Output(s):
// y = function value at x
//////////////////////////////////////////////////////////////////////////
y = cos(x) - sin(3*x);
endfunction
Combine the two codes above and execute in the scilab console window:
For interval -4 and 4 with a stopping criterion of 0.05% and 30 maximum number of iterations
Or
For interval 0 and 0.5 with a stopping criterion of 0.2% and 30 maximum number of iterations
2. Repeat step 1 until percentage approximate relative error ( 𝜀𝑎 (%)) is less than 𝜀𝑠 = 0.2%).
3. How the speed of convergence and the error tolerance (𝜀𝑠 ) are related?