//Evan Warner //Class computes and stores point and weight arrays for Gauss-Jacobi quadrature //Routine from Numerical Recipes in C, Second Edition //Initial approximations for roots given by Stroud and Secrest //Program continues with Newton's Method, using relation given by a polynomial and the polynomial //of one lower order to derive the derivative //Only provides weights/points for range [-1,1] //See MathWorld for more info including error term public class GaussJacobiWeights { private static double myAlpha, myBeta; private static double[] myPoints, myWeights; private static int myN; private static final int MAXIT=10; private static final double EPS=3.0*Math.pow(10,-14); //Floating-point tolerance of system public GaussJacobiWeights(double al, double be, int n) { myN=n; myAlpha=al; myBeta=be; myPoints = new double[myN]; myWeights = new double[myN]; double r1,r2,r3,z=0; for(int i=0;iMAXIT) System.out.println("SOMETHING'S FISHY"); //Should never get here under problem assumptions myPoints[i]=z; myWeights[i]=Math.exp(gammln(myAlpha+myN)+gammln(myBeta+myN)-gammln(myN+1.0)-gammln(myN+ab+1.0))*temp*Math.pow(2.0,ab)/(pp*p2); } } //Returns the natural logarithm of the gamma function applied to a real number x //Routine from Numerical Recipes in C, Second Edition, due to formula derived by Lanczos //Error is bounded by |e|<2*10e-10, not including roundoff error public double gammln(double x) { final double[] cof={76.18009172947146,-86.50532032941677,24.01409824083091,-1.231739572450155,0.001208650973866179,-0.000005395239384953}; double y=x; double temp=x+5.5; temp-=(x+0.5)*Math.log(temp); double ser=1.000000000190015; for(int j=0;j<=5;j++) { y++; ser+=cof[j]/y; } return -temp+Math.log(2.5066282746310005*ser/x); } //Returns weight array public double[] getWeights() { return myWeights; } //Returns point array public double[] getPoints() { return myPoints; } }