fork download
  1. program bisect
  2. real(8) :: output
  3.  
  4. call bisection(3.d0,4.d0,1.d-10,output)
  5. print*, output
  6. end program bisect
  7.  
  8. subroutine bisection(a,b,error,result)
  9. real(8):: a,b,error,c,result
  10. logical:: proceed
  11. proceed = .true.
  12. do while (proceed)
  13. if (sin(a)*sin(b).lt. 0.d0) then
  14. c=(a+b)/2
  15. if (sin(a)*sin(c).lt.0.d0) then
  16. b=c
  17. else
  18. a=c
  19. end if
  20. else
  21. stop 'cannot be bisected'
  22. end if
  23.  
  24. if (abs(a-b).lt. error) then
  25. proceed = .false.
  26. end if
  27. end do
  28. result= a
  29. end subroutine bisection
Runtime error #stdin #stdout 0s 3508KB
stdin
Standard input is empty
stdout
Standard output is empty