BISECTION1

 !Program name: BISECTION1

!Function: x^3-9

!Initial x value is 1.0

!Tolerance 1E-06

!initial Interval dx=0.5

!The number of bisections is indefinite

!Root is 2.08008382

 

Real :: x, dx, tolx

integer :: iter

 

y(x)=x**3-9

fold=y(x)   ! fold=-9.

 

tolx=1.E-06

x=1.

dx=0.5

iter=0

write (*,5) "iter", "x", "y(x)", "fold", "y(x)*fold", "dx"

5  format (a5X,a10X,a20X,a20X,a15X,a15X)

 

10 continue

    iter=iter+1

    x=x+dx

    print *,iter, x, y(x), fold, y(x)*fold, dx

       if ((fold*y(x)) .lt. 0.) then

         x=x-dx

         dx=dx/2

       end if

      if (abs(dx) .gt. tolx) goto 10

       stop

       end

Comentários

Postagens mais visitadas deste blog

HYDROGEN-RADIAL

HYDROGEN-POTENTIAL

ONE_PART_QHO