c From: "COMPUTATIONAL PHYSICS, 2nd Ed" c by RH Landau, MJ Paez, and CC Bordeianu c Copyright Wiley-VCH, 2007. c Electronic Materials copyright: R Landau, Oregon State Univ, 2007; c MJ Paez, Univ Antioquia, 2007; and CC Bordeianu, Univ Bucharest, 2007. c Support by National Science Foundation c c bessel.f: Spherical Bessel functions via up and down recursion c data saved as: x y1 y2 Program bessel Implicit none c order of Bessel function, x range, stepsize, start for downward alg Real*8 step, x, xmin, xmax, up, down, t1, t2 Integer order, start xmin = 0.25 xmax = 40.0 step = 0.1 order = 10 start = 50 c open output file Open(6, File = 'bessel.dat', Status = 'Unknown') c main program Do 10 x = xmin, xmax, step t1 = down(x, order, start) t2 = up(x, order) Write (6, *) x, t1, t2 10 Continue Close(6) Stop 'data saved in bessel.dat' End c calculate using downward recursion Function down(x, order, start) Implicit none Integer k, order, start Real*8 down, scale, x, j(100) c arbitrary start j(start+1) = 1 j(start) = 1 Do 20 k = start, 2, -1 j(k-1) = ((2*k-1.0)/x)*j(k)-j(k+1) 20 Continue c scale so that j(1) = sin(x)/x scale = (sin(x)/x)/j(1) down = j(order+1)*scale Return End c calculate using upward recursion Function up(x, order) Implicit none Integer k, order Real*8 up, x, one, two, thr one = sin(x)/x two = (sin(x)-x*cos(x))/(x*x) Do 30 k = 1, (order-1) thr = ((2*k+1.0)/x)*two-one one = two two = thr 30 Continue up = thr Return End