Java examples for java.lang:Math Number
Returns chi-square probability for odd numbers number.
//package com.java2s; public class Main { /**//from w w w .ja v a 2 s. co m * Returns chi-square probability for odd numbers number. */ public static double chiSquareProbOdd(int number, double value) { double result = 0; for (int idx = 0; idx <= (number / 2 - 1); idx++) { result += (1 / gammaFunction(idx + 1.5)) * Math.pow(value / 2, idx + 0.5); } return errFunction(Math.sqrt(value / 2)) - Math.exp(-value / 2) * result; } /** * Returns gamma value for a double in. */ public static double gammaFunction(double in) { if (in == 1.0) { return 1.0; } if (in == 0.5) { return Math.sqrt(Math.PI); } return (in - 1) * gammaFunction(in - 1); } /** * Returns error function for given double in. */ public static double errFunction(double in) { return (2 / Math.sqrt(Math.PI)) * Math.exp(-in * in) - 1; } }