Estimates the Digamma value of a real positive number. - Java java.lang

Java examples for java.lang:Math Number

Description

Estimates the Digamma value of a real positive number.

Demo Code


//package com.java2s;

public class Main {
    /**//from  ww  w .j a  v a  2  s.c om
     * Estimates the Digamma value of a real positive number.
     * 
     * @param x
     *            Input of the Digamma function.
     * @return The Digamma value for <code>x</code>.
     */
    private static double digamma(double x) {
        double p;
        assert x > 0;
        x = x + 6;
        p = 1 / (x * x);
        p = (((0.004166666666667 * p - 0.003968253986254) * p + 0.008333333333333)
                * p - 0.083333333333333)
                * p;
        p = p + Math.log(x) - 0.5 / x - 1 / (x - 1) - 1 / (x - 2) - 1
                / (x - 3) - 1 / (x - 4) - 1 / (x - 5) - 1 / (x - 6);
        return p;
    }
}

Related Tutorials