Monday, February 21, 2022

FORTRAN codes: Bisection method

c Bisection method

c Designed by Physics and Coding.

f(x)=j*x**2+k*x+l

22 write(*,*)'Give the quadratic equation coefficients a,b,c'

read(*,*)j,k,l

if(j.EQ.0) then

write(*,*)'This is a linear equation.'

d=-l/k

write(*,*)'The root is=>',d

goto 99

endif

11 write(*,*)'Give initial guesses x0,x1 & e'

read(*,*)x0,x1,e

y0=f(x0)

y1=f(x1)

i=0

if(y0*y1.GT.0) then

write(*,*)'The initial guesses are not suitable'

write(*,19)'Re-initialising the process...','....','...'

19 format(//,3x,a35,/,3x,a4,/,3x,a4)

goto 11

endif

do i=1,n 

if((abs(x1-x0)/x1).GT.e) then

x2=(x1+x0)/2

y2=f(x2)

endif

if(y2*y0.GT.0) then

x0=x2

y0=y2

else

x1=x2

y1=y2

endif

end do

write(*,*)'The root, value of f(x) and no. of iterations are',x2,y2,i

99 write(*,55)

55 format(1x,//,'Would you like to re-calculate?',/)

write(*,*)'Input 1 to recalculate'

write(*,*)'Input 2 to try another equation'

write(*,*)'Input anything other to exit'

read(*,*)a

if(a.EQ.1) then

goto 11

endif

if(a.EQ.2) then

goto 22

endif

end

No comments:

Post a Comment

FORTRAN Program: Centigrade to Fahrenheit conversion and vice-versa

 c Centigrade to Fahrenheit conversion and vice-versa c Designed by anonymous. real c,f 33 write(*,*)'Please select the conversi...

Popular Posts