! 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 ! ! Newton_fd.f90:Newton-Raphson root finder, forward diff derivative ! Program NewtonRHL_fd Implicit none Integer :: it, imax = 10 ! Max number iterations Real*8 :: x, dx = 1e - 2, eps = 1e - 6, df, F ! Guess must be close x = 2. Do it = 1, imax ! Forward difference derivative df = ( F(x + dx) - F(x) )/dx dx = - F(x)/df x = x + dx ! New guess write(*, *) it, x, F(x) ! Check for convergence If ( abs(F(x)) <= eps ) then write(*, *) eps Stop Endif End Do End ! Find zero of this function function F(x) Implicit none Real*8 :: x, F F = 2*cos(x) - x End