program bisection implicit double precision (a-h, o-z) c double precision f data a, b, tol/2.0d0, 3.0d0, 1.0d-06/ c c To parakatw programma ypologizei ena diasthma [a,b] mhkous c to poly tol to opoio periexei th riza ths exiswshs f(x)=0. c To programma ypo8etei oti f(a)f(b) < 0. c h = b - a n = 1 c fa = f(a) fb = f(b) do while(h .gt. tol) c = (a + b) / 2.0d0 if (c .eq. a .or. c .eq. b) goto 10 fc = f(c) if (fc .eq. 0.0d0) goto 10 c c H enyparxousa synarthsh sign orizetai ws exhs: c c | |a1|, an a2 >= 0 c sign(a1, a2) = | c | -|a1|, an a2 < 0 c if (dsign(1.0d0, fb) .ne. dsign(1.0d0, fc)) then a = c fa = fc else b = c fb = fc endif write(6, 20) n, c, fc, h h = h / 2.0d0 n = n + 1 enddo 10 write(6, 30) (a + b)/2.0d0, h 20 format(1x, i2, 1x, d16.9, 1x, d16.9, 1x, d16.9) 30 format(/1x, 'Root :', d16.9, /1x, 'Length :', d16.9) stop end c double precision function f(x) double precision x f = -5.0d0 - x * (2.0d0 - x * x) return end