포트란, 수치해석, 이분법, bisection method
Channel: Fortran Tutorial
Date: 2022-02-06

#포트란 #Numerical_method #이분법

     program bisection_method
     integer times
     real a,left,right,middle
     real one,half,zero,eps
     parameter(one=1.0,half=0.5,zero=0.0,eps=1.0e-6)
100  read(*,*,end=300)a
     write(*,500)a
500  format(f5.3)     
     times=0
     left=zero
     right=(a+one)*half
200  if(right-left.ge.eps)then
        times=times+1
        middle=(left+right)*half
        if(middle**2-a.gt.zero)then
           right=middle
        else
           left=middle
        endif
        write(*,400)times,middle,middle**2,right-left    
400     format(i5,2x,f10.7,2x,f10.7,2x,e10.5)        
        goto 200
     endif
     goto 100
300  stop
     endprogram bisection_method