Java tutorial
//package com.java2s; /* * Copyright bzewdu * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { public static double stDist(final double v, final double t) { double sm = 0.5; double sign = 1.0; final double stepSize = t / 5000.0; if (t < 0.0) { sign = -1.0; } else if (t == 0.0 || Double.isInfinite(t)) { return sm; } for (double u = 0.0; u <= sign * t; u += stepSize) { sm += stepSize * student_tDen(v, u); } if (sign < 0.0) { sm = 0.5 - sm; } else { sm = 1.0 - sm; } if (sm < 0.0) { sm = 0.0; } else if (sm > 1.0) { sm = 1.0; } return sm; } public static double student_tDen(final double v, final double t) { return student_c(v) * Math.pow(1.0 + t * t / v, -0.5 * (v + 1.0)); } public static double student_c(final double v) { return Math.exp(logGamma((v + 1.0) / 2.0)) / (Math.sqrt(3.141592653589793 * v) * Math.exp(logGamma(v / 2.0))); } public static double logGamma(final double xx) { final double stp = 2.50662827465; final double[] cof = { 76.18009173, -86.50532033, 24.01409822, -1.231739516, 0.00120858003, -5.36382E-6 }; double x = xx - 1.0; double tmp = x + 5.5; tmp = (x + 0.5) * Math.log(tmp) - tmp; double ser = 1.0; for (int j = 0; j < 6; ++j) { ++x; ser += cof[j] / x; } final double retVal = tmp + Math.log(2.50662827465 * ser); return retVal; } }