/* * GeneralisedGaussLaguerreQuadrature.java * * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard * * This file is part of BEAST. * See the NOTICE file distributed with this work for additional * information regarding copyright ownership and licensing. * * BEAST is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * BEAST is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with BEAST; if not, write to the * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ package dr.math; /** * Approximate the integral from min to +INF of x^alpha * e^-Bx * f(x) by generalised Gauss-Riemann quadrature * * Adapted from Numerical Recipes */ public class GeneralisedGaussLaguerreQuadrature implements Integral { private double B; private double alpha; final private int noPoints; final private double[] abscissae; final private double[] coefficients; public GeneralisedGaussLaguerreQuadrature(double B, double alpha, int noPoints){ this.B = B; this.alpha = alpha; this.noPoints = noPoints; abscissae = new double[noPoints]; coefficients = new double[noPoints]; setupArrays(); } public GeneralisedGaussLaguerreQuadrature(int noPoints){ this.noPoints = noPoints; abscissae = new double[noPoints]; coefficients = new double[noPoints]; } public void setB(double B){ this.B = B; setupArrays(); } public void setAlpha(double alpha){ this.alpha = alpha; setupArrays(); } public void setAlphaAndB(double alpha, double B){ this.alpha = alpha; this.B = B; setupArrays(); } private void setupArrays(){ final int maxIterations = 10; final double eps = 1E-14; double z = 0; double p1=0, p2=0, p3=0, pp=0; for(int i=0; i