Vous êtes sur la page 1sur 18

Numerical Methods (Laboratory)

Lab Report 1

Roots of Equations:
Bisection Method

Wayne Jude M. Bertumen


Name

GE41
section

November 20,2015
Date Submitted

OBJECTIVES:
Understand the process of finding root of
equation using bisection method.
Make a flowchart for the bisection method.
Make a program in octave that solves the root
of equation and shows the results in each
iteration.
Have 3 trials for each equation.
Make an observation and analysis for the
gathered data from the program that you have
created.

START

FlowChart

Initialize:
l,u,m,f(x),ea,es=0.5
,mold,mnew

Input:
l,u,f(x)

m=(l+u)/2; iter=1
;m=mold

Print iteration \t a \t b \t c \t
f(a) \t f(b) \t f(c) \t ea \n

Print iter \t l \t u \t m \t f(l)


\t f(u) \t f(m) \t ea \n

NO
NO

f(l)*f(u)=0

f(l)*f(u)<0

YES
f(u)=0
NO
Print:
root=l

f(l)*f(m)=0
YES

YES
Print:
root=u

NO

Print:
root=m

YES

END

Print:
Wrong
interval try
again

END

END

NO
f(l)*f(m)<0

END
u=m;

l=m;

iteration

iteration

iteration

m= (l+u)/2
; iter=iter+1 ;m=mnew

mnew=0

ea=inf

ea=(mnew-mold)*100/mnew

Print iter \t l \t u \t m \t f(l)


\t f(u) \t f(m) \t ea \n

ea<es

Print:
root=m

f(l)*f(m)<0

u=m;
mold=m

l=m;
mold=m

m
iteration

iteration

Algorithm / Code :
%f is for function , l is lower interval , u is upper interval ,
function root=bisection(f,l,u)
es=0.5;
fprintf('Interval: ');fprintf('%3.4f', l);fprintf(',');fprintf('%3.4f', u);fprintf('\n');
fprintf('Stopping criterion es= ');fprintf('%3.4f',
es);disp('%'); disp('Using Bisection, the result can be
summarized as'); m=(l+u)/2;
mold=m;
iters=257
; iter=1;
fprintf('iteration ');fprintf('a \t');fprintf('b \t');fprintf('c \t');fprintf('f(a) \t');fprintf('f(b) \t');fprintf('f(c) \t');
disp('|ea|%');
fprintf('%i', iter);fprintf('\t');
fprintf('%3.4f', l);fprintf('\t');
fprintf('%3.4f', u);fprintf('\t');
fprintf('%3.4f',
m);fprintf('\t');
fprintf('%3.4f',
f(l));fprintf('\t');
fprintf('%3.4f',f(u));fprintf('\t'
); fprintf('%3.4f',
f(m));fprintf('\t');
fprintf('100');fprintf('\n');
chk=f(l)*f(u);
if (chk==0)
chk=f(u);
if( chk==0) root=u;
fprintf('root=');fprintf('%3.4f',root);fprintf(
'\n');

else root=l;
fprintf('root=');fprintf('%3.4f',root);fprintf(
'\n');

endif
else
if(chk<0)
chk=f(l)*f(m)
; if (chk==0)
root=m;
fprintf('root=');fprintf('%3.4f',root);fprintf('\n');

elseif(chk<0) u=m;
iteration(iter,l,u,f,mold,es,ite
rs); else
l=m;
iteration(iter,l,u,f,mold,es,ite
rs); endif

else
disp("Incorrect input of interval. Try again");
endi
f
endi
f

function[]=iteration(iter,l,u,f,mold,es,iters)
m=(l+u)/2;
mnew=m;
iter=iter+1;
if(iter~=iters+1
)

if(mnew==0)
ea=inf;
else
ea=(abs((mnew-mold)/mnew))*100;
endif
fprintf('%i', iter);fprintf('\t');
fprintf('%3.4f', l);fprintf('\t');
fprintf('%3.4f', u);fprintf('\t');
fprintf('%3.4f',
m);fprintf('\t');
fprintf('%3.4f',
f(l));fprintf('\t');
fprintf('%3.4f',f(u));fprintf('\t'
); fprintf('%3.4f',
f(m));fprintf('\t');
fprintf('%3.4f',
ea);fprintf('\n');
if (ea<es) root=m;
fprintf('root=');fprintf('%3.4f',root);fprintf(
'\n');

else
chk=f(l)*f(m)
; if(chk<0)
u=m; mold=m;
iteration(iter,l,u,f,mold,es,ite
rs); else
l=m; mold=m;
iteration(iter,l,u,f,mold,es,ite
rs); endif
endif else
fprintf('root=');fprintf('%3.4f',m);fprintf('
\n');

break;
end

Data and Results


1.

True Value(using calculator shift solve):1.465571232

First interval (-2,3)

Second interval (-8,12)

Third interval (-20,25)

2.

True Value(using calculator shift solve):0.6529186


Interval 1: (-1,1.5)

Interval 3 :(-20,21)

3.

True Value(using calculator shift solve):0.56714


First Interval (0,1.5)

Second Interval (0,8)

Third Interval (0,25)

4.f(x)=sqrt(x) -cos(x)

True Value(using calculator shift solve):0.6417143


First Interval(0,1.5)

Second Interval (0,30)

Third Interval (0,300

Observation:
The observation that I saw in this is experiment is that as the length of the
guess interval gets wider the number of iteration also increases. It is a good
assumption to take wide intervals so that you can have assurance that the root of
the equation is in that interval with reference that f(u)*f(l)<0 ,but it will take longer
for the program to find the roots of your equation because it will solve more
equations. The tradeoff of getting assuming large interval in bisection method is
the time before convergence. Bisection moves in a very predictable way because
it cuts the interval in half and then finds where it is located in the upper or lower
half so if you set a big interval it would take the program longer to converge.
In using 0.5% of stopping criterion it can be observed in the results that in
the three intervals in each equation their outputs are the same up to two decimal
places compared to each other and the true value that I got from the calculator.
If you would decrease the stopping criterion it would make the result of the roots
more accurate and precise with each other and with its true value but then again
it will take more time for the program to solve for the roots and to find
convergence in the results.
Analysis:
Bisection method uses a very simple yet effective algorithm in finding a root
of a given equation. Although it uses a somewhat brute force attack on its
process because it just finds the product of f(u) and f(l) that will make it negative.
The process of bisection is rooted to the intermediate value theorem which stated
that the if f(x)=0, then f(xu)*f(xl) should have a negative value to say that the root
is between your assumed interval. The wider your interval is the longer is the
convergence, the longer your convergence the longer it takes the computer to
solve the problem therefore it decreases efficiency in work. In the problems
stated the delay is not felt but if you will input longer and complex equations it
would be felt. It also depends on speed of the computer but as designers it is our
job to make the program as efficient as possible. In the stopping criterion you can
say that the results are correct for it reflects the equation = (0.5102 )% where
n is number of atleast significant digits. In the results gathered compared to the
value from the calculator it is correct up to 2 to 3 decimal places therefor we
achieved the goal of 0.5% stopping criterion. If you want to make the results more
precise and accurate you have to decrease the stopping criterion or compute for
it and plug in a high number in the n or the number of significant digits but the
downside is that it will take longer for the program to converge.
I conclude that this method should be seldom used because of its
inefficiency with wider initial intervals. But if time of convergence is not a big
factor in your design then you should use this because of its simple algorithm.

Vous aimerez peut-être aussi