Java Gamma Gamma(double z)

Here you can find the source of Gamma(double z)

Description

Gamma

License

LGPL

Declaration

public static double Gamma(double z) 

Method Source Code

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

public class Main {
    public static double Gamma(double z) {
        double total = 0.0;
        double step = (10 * z) / 1000;
        double t = 0;
        double r = z - 1;
        double last = Math.pow(t, r);

        for (t = step; t < 10 * z; t += step) {
            double next = Math.pow(t, r) * Exp(-t);
            total += TrapeziumArea(step, last, next);
            last = next;/*from w w w . jav a2 s .c o m*/
        }

        return total;
    }

    /**
     * raises a number to the power e
     * 
     * @param d
     * @return e^d
     */
    public static double Exp(double d) {
        return Math.pow(Math.E, d);
    }

    /**
     * calculates the area of a trapezium
     * 
     * @param width
     *            the width accross the trapezium
     * @param a
     *            side length of side a
     * @param b
     *            side length of side b
     * @return the area of the trapezium
     */
    public static double TrapeziumArea(double width, double a, double b) {
        return (0.5 * width * (a + b));
    }
}

Related

  1. gamma(double x)
  2. gamma(double x)
  3. gamma(double x)
  4. gamma(double x)
  5. gamma(int alpha)
  6. gamma(int rgb)
  7. gammaCdf(double a, double x)
  8. gammaCdf(double a, double x)