0% found this document useful (0 votes)
42 views6 pages

Activity No. 1 Iterative Methods For Solving Roots of Functions I A. Bisection Method (Half-Interval Method)

The document describes iterative root-finding methods including the bisection method, method of false position, Newton's method, secant method, and fixed-point iterative method. Algorithms for each method are provided along with sample programs to solve the equation f(x) = 1+x^2e^-0.2x - x^3 using each method.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views6 pages

Activity No. 1 Iterative Methods For Solving Roots of Functions I A. Bisection Method (Half-Interval Method)

The document describes iterative root-finding methods including the bisection method, method of false position, Newton's method, secant method, and fixed-point iterative method. Algorithms for each method are provided along with sample programs to solve the equation f(x) = 1+x^2e^-0.2x - x^3 using each method.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

ACTIVITY NO.

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)

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).
SAMPLE PROGRAMS:
A. Sample Program for Bisection 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;

//Half-Interval Method
disp('HALF-INTERVAL METHOD');
e=input('Error tolerance:');

//prompt for a correct pair of limits


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;

//iterate until an aceptable root is computed


xr=0.5*(xL+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=0.5*(xU+xL);
n=n+1;
IT=[IT;n,xr,f(xr)];
end;

//display the iteration table and computed root


IT
xr
B. Sample Program for Method of False Position : 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;

//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);

//Function for evaluating f(x)


function fv=f(x)
fv=1+(x.^2)*exp(-0.2*x)-x^3;
endfunction;

//Function for evaluating f'(x) using numerical differentiation


function fpv=fp(x)
dx=10^(-12);
fpv=(f(x+dx)-f(x))/dx;
endfunction;

//Newton-Raphson Method
disp('NEWTON METHOD');
e=input('Error tolerance:');
xr=input('First trial root:');

nmax=100; //maximum number of iterations


n=1;//initialize the iteration counter n
IT=[n,xr,f(xr)];//initialize the iteration table IT
while (abs(f(xr))>e & n<=nmax )
xr=xr-f(xr)/fp(xr);
n=n+1;
IT=[IT;n,xr,f(xr)];
end;

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:');

nmax=100;//maximum number of iterations


xr=input('First trial root:');
n=1; IT=[n,xr,f(xr)];
while(abs(f(xr))>e & n<nmax)
xrn_1=xr;
xr=input('Second trial root:');
n=n+1;IT=[IT;n xr, f(xr)];
while(abs(f(xr))>e & n<nmax)
xrn_2=xrn_1;
xrn_1=xr;
xr=xrn_1-(f(xrn_1)*(xrn_2-xrn_1))/(f(xrn_2)-f(xrn_1));
n=n+1; IT=[IT;n xr, f(xr)];
end;
end;

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;

C. Sample Program for Fixed-Point Iterative Method: f(x) = 1+x2e-0.2x-x3

clear; clc; format(12)

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:');

xr=input('Initial trial root:');


nmax=100;
n=1; IT=[n,xr,f(xr)];
while abs(f(xr))>e & n<nmax
xr=g(xr);
n=n+1; IT=[IT; n, xr, f(xr)];
end
if abs(f(xr))>e then
disp('No root found.')
disp(' Try a new initial trial root or change g(x)');
else
IT
xr
end
ACTIVITY NO. 3
ITERATIVE METHODS FOR SOLVING ROOTS OF FUNCTIONS III
Algorithm for Bairstow Method:
Bairstow method is used to factor a polynomial f(x) = anxn + an-1xn-1 + ... + a1x + a0 as
f(x) = q(x)p(x) where q(x) is a quadratic factor and p(x) is the deflated polynomial.
Given a polynomial f(x) = anxn + an-1xn-1 + ... + a1x + a0,
1. Assume a trial quadratic factor q(x) = x2- rx - s and error tolerance ε.
2. Compute for b-coefficients using the following recursive formulas.
bn = an
bn-1 = an-1 + r bn
bk = ak + r bk+1 + s bk+2 , for k=(n-2) to 0
3. Compute for c-coefficients using the following recursive formulas.
cn = bn
cn-1 = bn-1 + r cn
ck = bk + r ck+1 + s ck+2 , for k=(n-2) to 1
4. Compute for the incremental change ∆r and ∆s.
b0c3 - b1c2 b1c1 - b0c2
∆r = -------------------- ∆s = ----------------------
c22 - c1c3 c22 - c1c3
5. While |∆r|>ε or |∆s|>ε

- 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

n=1; IT=[n,q]; //Initialize the iteration table


r=-q(2); s=-q(3);
m=length(a);

//Compute the b-coefficients


b(1,1)=a(1);
b(1,2)=a(2)+r*b(1,1);
for k=3:m
b(1,k)=a(k)+r*b(1,k-1)+s*b(1,k-2);
end;
//Compute the c-coefficients
c(1,1)=b(1);
c(1,2)=b(2)+r*c(1,1);
for k=3:(m-1)
c(1,k)=b(k)+r*c(1,k-1)+s*c(1,k-2);
end;
//Compute dr and ds
dr=(-b(m-1)*c(m-2)+b(m)*c(m-3))/(c(m-2)^2-c(m-1)*c(m-3));
ds=(-b(m-1)*c(m-1)+b(m)*c(m-2))/(c(m-1)*c(m-3)-c(m-2)^2);

//Iterate while |dr| or |ds| is greater than e


while ( abs(dr)>e | abs(ds)>e)
q=[1, -(r+dr), -(s+ds)];
n=n+1; IT=[IT; n,q];
r=-q(2); s=-q(3);
m=length(a);
//Compute the b-coefficients
b(1,1)=a(1);
b(1,2)=a(2)+r*b(1,1);
for k=3:m
b(1,k)=a(k)+r*b(1,k-1)+s*b(1,k-2);
end;
//Compute the c-coefficients
c(1,1)=b(1);
c(1,2)=b(2)+r*c(1,1);
for k=3:(m-1)
c(1,k)=b(k)+r*c(1,k-1)+s*c(1,k-2);
end;
//Compute dr and ds
dr=(-b(m-1)*c(m-2)+b(m)*c(m-3))/(c(m-2)^2-c(m-1)*c(m-3));
ds=(-b(m-1)*c(m-1)+b(m)*c(m-2))/(c(m-1)*c(m-3)-c(m-2)^2);
end;

IT //display the iteration table


q //display the coefficients of the quadratic factor
p=b(1:(m-2)) //display the coefficients of the deflated polynomial

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.

You might also like