Vous êtes sur la page 1sur 3

FORTRAN 90

Lecturer : Rafel Hekmat Hameed University of Babylon

Subject : Fortran 90 College of Engineering

Year : Second B.Sc. Mechanical Engineering Dep.

S
SOOL
LUUTTIIO
ONN O
OFF N
NOON
N--L
LIIN
NEEA
ARR E
EQQU
UAATTIIO
ONN

Bisection Method
The bisection method in mathematics is a root-finding method which
#_> #_>
repeatedly bisects an interval and then selects a subinterval in which a root
#_> #_>
must lie for further processing. It is a very simple and robust method, but it is
also relatively slow. Because of this, it is often used to obtain a rough
approximation to a solution which is then used as a starting point for more
rapidly converging methods.

Consider a transcendental equation f (x) = 0 which has a zero in the


interval [a,b] and f (a)  f (b) < 0. We may refine our approximation to the
root by dividing the interval into two: find the midpoint c = (a + b)/2. In any
real world problem, it is very unlikely that f(c) = 0, however if we are that
lucky, then we have found a root. More likely, if f(a) and f(c) have opposite
signs, then a root must lie on the interval [a, c]. The only other possibility is
that f(c) and f(b) have opposite signs, and therefore the root must lie on the
interval [c, b].

We may repeat this process numerous times, each time halving the size
of the interval.

Numerical Example :
Find a root of f (x) = 3x + sin(x) - exp(x)=0.

The graph of this equation is given in the


figure.

ϭ
It's clear from the graph that there are two roots, one lies between
0 and 0.5 and the other lies between 1.5 and 2.0. Consider the function
f (x) in the interval [0, 0.5] since f (0)  f (0.5) is less than zero. Then the
bisection iterations are given by

Iteration
a b c f(a)  f(c)
No.
1 0 0.5 0.25 0.287 (+ve)
2 0.25 0.5 0.393 -0.015 (-ve)
3 0.25 0.393 0.34 9.69 E-3 (+ve)
4 0.34 0.393 0.367 -7.81 E-4 (-ve)
5 0.34 0.367 0.354 8.9 E-4 (+ve)
6 0.354 0.367 0.3605 -3.1 E-6 (-ve)

So one of the roots of 3x + sin(x) - exp(x) = 0 is approximately 0.3605.

program bisection

implicit none

real,parameter::error=1e-4

real::a,b,f,c

10 read(*,*) a,b

15 if (f(a)*f(b).lt.0)then

c=(a+b)/2.0

else

write(*,*)"try with another value of a & b "

Ϯ
goto 10

endif

if(f(a)*f(c).lt.0)then

b=c

else

a=c

endif

if(abs(b-a).gt.error)goto 15

write(*,*)"the root is=",c

end

real function f(x)

implicit none

real::x

f=3*x + sin(x) - exp(x)

end

Vous aimerez peut-être aussi