Here you can find the source of gammaOfArgOn2Plus1(int d)
Computes gamma(d/2 + 1) See http://en.wikipedia.org/wiki/Gamma_function for description of the analytical result for d odd.
Parameter | Description |
---|---|
d | a parameter |
public static double gammaOfArgOn2Plus1(int d)
//package com.java2s; /*// w w w . j a v a 2 s . c o m * Java Information Dynamics Toolkit (JIDT) * Copyright (C) 2012, Joseph T. Lizier * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Computes gamma(d/2 + 1) * See http://en.wikipedia.org/wiki/Gamma_function * for description of the analytical result for d odd. * For d even, we have gamma of an integer, which is equal to * (d/2)! * * @param d * @return */ public static double gammaOfArgOn2Plus1(int d) { if (d % 2 == 0) { // d even return factorialAsDouble(d / 2); } else { // d odd return Math.sqrt(Math.PI) * (double) doubleFactorialAsDouble(d) / (double) Math.pow(2, ((double) (d + 1)) / 2.0); } } public static double factorialAsDouble(int n) { double result = 1; for (int i = 1; i <= n; i++) { result *= (double) i; } return result; } /** * n!! * see http://en.wikipedia.org/wiki/Double_factorial#Double_factorial * * @param n * @return */ public static double doubleFactorialAsDouble(int n) { double result = 1.0; int startValue; if (n % 2 == 0) { // n even startValue = 2; } else { // n odd startValue = 3; } for (int i = startValue; i <= n; i += 2) { result *= (double) i; } return result; } }