! From: "COMPUTATIONAL PHYSICS 2nd Ed" ! by RH Landau, MJ Paez, and CC Bordeianu ! Copyright Wiley-VCH, 2007. ! Electronic Materials copyright: R Landau, Oregon State Univ, 2007; ! MJ Paez, Univ Antioquia, 2007; and CC Bordeianu, Univ Bucharest, 2007. ! Supported by the US National Science Foundation ! ! diff.f90: Forward, central and extrapolated differentiation Program diff Implicit none Real*8 :: f, h, result(3), x, xmin, xmax, xstep open(6, File = 'diff.dat', Status = 'Unknown') h = 1.e-5 xmin = 0.0 xmax = 7.0 xstep = 0.01 Do x = xmin, xmax, xstep result(1) = (f(x+h) - f(x))/h result(2) = (f(x+h/2) - f(x-h/2))/h result(3) = (8*(f(x+h/4)-f(x-h/4)) - (f(x+h/2)-f(x-h/2)))/(3*h) write (6, 20) x, result(1), result(2), result(3) End Do 20 Format(F5.3, TR4, F10.8, TR4, F10.8, TR4, F10.8) close(6) Stop 'data saved in diff.dat' End Program diff ! function to integrate Function f(x) Implicit none Real*8 f, x f = cos(x) Return End