Java Digamma digamma(double x)

Here you can find the source of digamma(double x)

Description

Compute the value of digamma function

License

Apache License

Parameter

Parameter Description
x a parameter

Declaration

public static double digamma(double x) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static final double c1 = -0.5;
    public static final double c2 = -1.0 / 12;
    public static final double c4 = 1.0 / 120;
    public static final double c6 = -1.0 / 252;

    /**/*w  w  w . j a  va  2s .co m*/
     * Compute the value of digamma function
     *
     * @param x
     * @return
     */
    public static double digamma(double x) {
        double y, y2, sum = 0;
        for (y = x; y < 10; y++) {
            sum -= 1.0 / y;
        }
        y2 = 1.0 / (y * y);
        sum += Math.log(y) + c1 / y + y2 * (c2 + y2 * (c4 + y2 * c6));
        return sum;
    }
}

Related

  1. digamma(double x)
  2. digamma(double x)
  3. digammaByDefinition(int d)
  4. digammaDiff(double x, int d)