BONGOS

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

KYAMBOGO UNIVERSITY

FACULTY OF ENGINEERING

DEPARTMENT OF CIVIL AND BUILDING ENGINEERING


BACHELOR OF VOCATIONAL STUDIES AND TECHNOLOGICAL STUDIES
WITH EDUCATION
TEEM 2101 ENGINEERING MATHMATICS REPORT ON MATLAB
LECTURER: ENYOGOI ISAAC
NAME REGISTRATION NUMBER SIGN
LAKICA JESCA 18/U/VTD/15069/PD
KANYESIGYE COLLINS 18/U/VTD/18035/GV
SEBINTENE CHRISTOPHER 18/U/VTD/044/GV
BONGOMIN JOSHUA 18/U/VTD/041/GV

A REPORT SUBMITTED IN PARTIAL FULFILLMENT OF THE


REQUIREMENTS OF A BACHELOR’S DEGREE IN VOCATIONAL AND
TECHNOLOGICAL STUDIES WITH EDUCATION OF KYAMBOGO
UNIVERSITY.
SEPTEMBER 2019
METHODS.
The bisection method
If f(x) is a function and continuous on an interval [x0,x1], such that f(x0)f(x1) < 0 , it follows
that there exists at least one root of f in (x0,x1). we assume that f has exactly one root α.
Then we halve the interval [x0,x1] to determine a smaller and smaller interval within which the
root must lie. We first define the midpoint of [x0,x1], x = (xo + x1)/2 and then computing the
product f(x)f(x1). If the product is negative, then the root is in the interval [x,x1]. If the product
is positive, then the root is in the interval [x0,x]. Thus, a new interval containing the root is
obtained. We continue halving the new interval continues until the root is located as accurately as
desired.
We plotted the curve of the function x^2-5 to determine x0 and x1.

As expected, the curve shows one crossing between 2 and 3 , so we take 2 as our first
approximation,
The commands were ran as below;
f=@(x) x.^2-5;
x0=2;
x1=3;
tolx=1e-10;
tic
for i=1:30
x=(x0+x1)/2;
if f(x)*f(x1)<0
x0 = x;
else
x1 = x;
end

err = abs(x0-x1);
if err<tolx
break
end
end
toc
fprintf('the root is : %f\nthe number of iterations are: %d\n',x,i)
this was the result after running the command.
Elapsed time is 0.010359 seconds.
the root is : 2.236068
the number of iterations are: 30

Newton Raphson method


This method uses a tangent line. To use the method we begin with an initial guess x0,
sufficiently close to the root α, x0 is got by plotting the graph of the function and determining
the value before the curve crosses the x axis. The next approximation x1 is given by the point at
which the tangent line to f at f(x0,f(x0)) crosses the x-axis. It is clear that the value x1 is much
closer to α than the original guess x0. If xn+1 denotes the value obtained by the succeeding
iterations, that is the x-intercept of the tangent line to f at (xn,f(xn)), then a formula relating xn
and xn+1, known as Newton’s method provided f′(xn) is not zero.
The following were the commands.
%f(x)=x.^2-5
x0=2;
tolx=1e-6;
x=x0;
xold=x0;
tic
for i=1:30
f=x.^2-5;
df=2*x;
x=x-f/df;
err=abs(xold-x);
xold = x;
if err<tolx
break;
end
end
toc
fprintf('the root is : %f\nthe number of iterations are: %d\n',x,i)
And the results were obtained as follows.

Elapsed time is 0.005340 seconds.


the root is : 2.236068
the number of iterations are: 4
The secant method
it is based on approximating the function by a straight line connecting two points on the graph of
the function f.
In this method, the first point, x2, of the iteration is taken to be the point of intersection of the x-
axis and the secant line connecting two starting points (x0,f(x0)) and (x1,f(x1)). The next point,
x3, is generated by the intersection of the new secant line, joining (x1,f(x1)) and (x2,f(x2)) with
the x-axis. The new point, x3, together with x2, is used to generate the next point, x4, and so on
xn+1 depends on the two previous elements of the sequence and therefore two initial guesses, x0
and x1, must be provided to generate x2,x3 and so on.
The following commands were used.
f=@(x) x.^2-5;
x0=2;
x1=3;
tolx=1e-6;
tic
for i=1:50
xn=((x0*f(x1))-(x1*f(x0)))/(f(x1)-f(x0));
if abs(f(xn)-f(x1))>=tolx
x0=x1;
x1=xn;
else
break
end
end
toc
fprintf('the root is : %f\nthe number of iterations are: %d\n',xn,i)

yielding the following result.


Elapsed time is 0.004825 seconds.
the root is : 2.236068
the number of iterations are: 5
Rate of convergence of secant method.
Newton Raphson method.
%f(x)=x^2-5
x0=2;
tolx=1e-6;
x=x0;
xold=x0;
tic
for i=1:30
f=x.^2-5;
df=2*x;
x=x-f/df;
fprintf('iteration=%d\tx0=%f\tx=%f\n',i,x0,x)
err=abs(x0-x);
x0 = x;
if err<tolx
break;
end
end
toc
results.
iteration=1 x0=2.000000 x=2.250000
iteration=2 x0=2.250000 x=2.236111
iteration=3 x0=2.236111 x=2.236068
iteration=4 x0=2.236068 x=2.236068
Elapsed time is 0.001588 seconds
Secant method
f=@(x) x^2-5;
x0=2;
x1=3;
tolx=1e-6;
tic
for i=1:50
x2=((x0*f(x1))-(x1*f(x0)))/(f(x1)-f(x0));

fprintf('iteration=%d\tx0=%f\tx=%f\n',i,x0,x1)
if abs(f(x2)-f(x1))>=tolx
x0=x1;
x1=x2;
else
break
end
end
toc
results
iteration=1 x0=2.000000 x=3.000000
iteration=2 x0=3.000000 x=2.200000
iteration=3 x0=2.200000 x=2.230769
iteration=4 x0=2.230769 x=2.236111
iteration=5 x0=2.236111 x=2.236068
Elapsed time is 0.020749 seconds

CONCLUSION
Based on our results and discussions, we concluded that the secant method is formally the most
effective of the methods we have considered here in the study. This is to the fact that it has a
converging rate close to that of newton Raphson method but requires only a single function
evaluation per iteration. We also concluded that though the conversion of bisection is certain, its
rate of convergence is too slow and as such it is difficult to extend to use for systems of equation.
Therefore we would recommend someone to use the secant method because it requires only
evaluation of the function

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy