/* 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. Support by National Science Foundation */ // Bessel.java: Spherical Bessels via up and down recursion import java.io.*; public class bessel { // Global class variables public static double xmax = 40., xmin = 0.25, step = 0.1; public static int order = 10, start = 50; public static void main(String[] argv) throws IOException, FileNotFoundException { double x; PrintWriter w = new PrintWriter(new FileOutputStream("Bessel.dat"), true); // Step thru x values for ( x = xmin; x <= xmax; x += step ) w.println(" " +x+" "+down(x, order, start) ); System.out.println("data stored in Bessel.dat"); } // End main public static double down (double x, int n, int m) { // Recur down double scale; double j[] = new double[start + 2]; int k; // Start with anything j[m + 1] = j[m] = 1.; for ( k = m; k>0 ; k--) j[k-1] = ((2.*k+1.)/x)*j[k] - j[k+1]; // Scale solution to known j[0] scale = (Math.sin(x)/x)/j[0]; return j[n] * scale; } }