Activity No. 1 Iterative Methods For Solving Roots of Functions I A. Bisection Method (Half-Interval Method)
Activity No. 1 Iterative Methods For Solving Roots of Functions I A. Bisection Method (Half-Interval Method)
1
ITERATIVE METHODS FOR SOLVING ROOTS OF FUNCTIONS I
A. Bisection Method ( Half-Interval Method)
Algorithm for Bisection Method:
1. Assume values for the lower limit xl and the upper limit xu of the interval xl≤x≤xu such that the
root is included in the interval. The root is in the interval if f(xl)f(xu)<0.
2. Compute the trial value of the root as xr=0.5(xl+xu).
3. Test if the trial value of the root is acceptable.
The trial value of the root is acceptable if |f(xr)|<10-12.
4. While the trial value of the root is not acceptable, do the following:
4.a. Reduce the interval.
If f(xl)f(xr)<0 then xu=xr else xl=xr.
4.b. Compute a new trial value of the root as xn=0.5(xl+xu).
B. Method of False Position (Regula-Falsi Method)
Algorithm for Method of False Position:
1. Assume values for the lower limit xl and the upper limit xu of the interval xl≤x≤xu such that the
root is included in the interval. The root is in the interval if f(xl)f(xu)<0.
2. Compute the trial value of the root by interpolating a line passing through (xL,f(xL)) and (xU,f(xU)).
f(xL) {xL-xU}
xr = xL - ---------------------
f(xL) - f(xU)
clear;clc;format(12);
//Half-Interval Method
disp('HALF-INTERVAL METHOD');
e=input('Error tolerance:');
clear;clc;format(12);
//Regula-Falsi Method
disp('REGULA-FALSI METHOD');
e=input('Error tolerance:');
xL=input('Lower Limit:');
xU=input('Upper Limit:');
while(f(xL)*f(xU)>0)
disp('The limits do not enclose the root. Enter new limits.')
xL=input('Lower Limit:');
xU=input('Upper Limit:');
end;
xr=xL-(f(xL)*(xL-xU))/(f(xL)-f(xU));
n=1;//initialize the iteration counter n
IT=[n,xr,f(xr)];//initialize the iteration table IT
while (abs(f(xr))>e)
if f(xL)*f(xr)<0 then
xU=xr;
else
xL=xr;
end;
xr=xL-(f(xL)*(xL-xU))/(f(xL)-f(xU));
n=n+1;
IT=[IT;n,xr,f(xr)];
end;
IT
xr
ACTIVITY NO. 2
ITERATIVE METHODS FOR SOLVING ROOTS OF FUNCTIONS II
A. Newton Method
Algorithm for Newton Method:
1. Assume an initial trial root xr.
2. Test if the trial value of the root is acceptable.
The trial value of the root is acceptable if |f(xr)|<10-12.
3. While the trial value of the root is not acceptable, compute a new trial root xr by interpolating a
line that is tangent to f(x) at (xr,f(xr)).
f(xr)
new xr = xr - --------
f '(xr)
f(xr+dx) - f(xr)
with f '(xr) = lim --------------------
dx 0 dx
B. Secant Method
Algorithm for Secant Method:
1. Assume the first trial root xr.
2. Test if the trial value of the root is acceptable. The trial value of the root is acceptable if |f(xr)|<10-12.
3. Assume the second trial root xr.
4. Test if the trial value of the root is acceptable.
5 While the trial value of the root is not acceptable, compute a new trial root xr by interpolating a
line through the points corresponding to the last two trial roots.
f(xrn-1){xrn-2 - xrn-1}
xrn = xrn-1 - ---------------------------- , for n≥3
f(xrn-2) - f(xrn-1)
where: xrn - new trial root
xrn-1 - immediately preceding trial root
xrn-2 - trial root at two trials earlier
C. Fixed-Point Iterative Method
Algorithm for Fixed-Point Iterative Method
1. Rewrite f(x)=0 as x=g(x).
2. Assume the first trial root xr.
3. Test if the trial value of the root is acceptable. The trial value of the root is acceptable if |f(xr)|<10-12.
4 While the trial value of the root is not acceptable, compute a new trial root xr using the fixed-
point equation.
new xr = g(xr)
SAMPLE PROGRAMS:
A. Sample Program for Newton Method : f(x) = 1+x2e-0.2x-x3
clear;clc;format(12);
//Newton-Raphson Method
disp('NEWTON METHOD');
e=input('Error tolerance:');
xr=input('First trial root:');
if abs(f(xr))>e then
disp('No root found.Rerun the program and try a new initial trial root');
else
//display the iteration table and computed root
IT
xr
end;
B. Sample Program for Secant Method : f(x) = 1+x2e-0.2x-x3
clear;clc;format(12);
//Function for evaluating f(x)
function fv=f(x)
fv=1+(x.^2)*exp(-0.2*x)-x^3;
endfunction;
//Secant Method
disp('SECANT METHOD');
e=input('Error tolerance:');
if abs(f(xr))>e then
disp('No root found.Rerun the program and try new initial trial roots');
else
//display the iteration table and computed root
IT
xr
end;
function fv=f(x)
fv=1+(x^2)*exp(-0.2*x)-x^3;
endfunction
function gv=g(x)
gv=(1+(x^2)*exp(-0.2*x))^(1/3);
endfunction
//Method of Successive Substitution
disp('FIXED-POINT ITERATIVE METHOD');
e=input('Error tolerance:');
- let the new trial quadratic factor be q(x) = x2 - (r+∆r)x - (s+∆s) such that
new r = r+∆r and new s = s+∆s
- generate b-coefficients
- generate c-coefficients
- compute ∆r and ∆s
6. The quadratic factor is q(x) and the deflated polynomial is p(x)=bnxn-2 + bn-1xn-3 +...+ b3x + b2.
SAMPLE PROGRAM:
Sample Program for Bairstow Method:
Let f(x)=x5-2x4-15x3-12x2+44x+80 and initial trial quadratic factor be q(x)=x2+4x-3
clear; clc;
//BAIRSTOW METHOD
disp('BAIRSTOW METHOD');
a=input('Polynomial Coefficients:'); // Polynomial Coefficients:[1, -2, -15, -12, 44, 80]
q=input('Trial Quadratic Factor:'); // Trial Quadratic Factor:[1, 4,-3]
e=input('Error Tolerance:'); // Error Tolerance:10^-12
The program results to q=[1, -3, -10] and p =[1, 1, -2, -8] after 9 iterations. This indicates that f(x) can be factored as f(x)= (x2-3x-10)( x3+x2-
2x-8). Bairstow Method can be used again to factor the cubic factor.