BISECTION2

 !Program name: BISECTION2

!Function: x^3-9

!Initial x value is 1.0

!Tolerance 1E-06

!initial Interval dx=0.5

!The number of bisections is 100

!Root is 2.08008382

 

Real :: x, dx, y, fold

Real :: tolx

integer :: iter, i

 

func(x)=x**3-9

fold=func(x)

 

tolx=1.E-06

x=1.

dx=0.5

iter=100

 

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

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

 

do i=0,iter

     x=x+dx

     y=func(x)

    print *,i, x, y, fold, fold*y, dx

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

         x=x-dx

         dx=dx/2

       end if

      

       if (abs(dx) .gt. tolx) cycle

       if (abs(dx) .lt. tolx) exit

 

  end do

       stop

       end

Comentários

Postagens mais visitadas deste blog

DATA

HYDROGEN-RADIAL

HYDROGEN-POTENTIAL