累積分布関数を計算するための関数及びテスト用のコード。
package info.pandanote.normdist; | |
public class NormDistTest { | |
public double normDist(double x) { | |
if (x == 0.0) { | |
return 0.5; | |
} | |
double ax = x; | |
double deltaax = x; | |
int k = 0; | |
while (Math.abs(deltaax/ax) > 1e-12) { | |
deltaax *= x*x*((double)(-(2*k+1)))/(2*k+3)/(2*k+2); | |
//System.out.println("deltaax="+deltaax); | |
ax += deltaax; | |
//System.out.println("ax="+ax); | |
k++; | |
} | |
//System.out.println("k="+k); | |
return ax/Math.sqrt(2.0*Math.PI)+0.5; | |
} | |
public static void main(String[] args) { | |
NormDistTest ndt = new NormDistTest(); | |
double x = 0.0; | |
System.out.println("f("+x+")="+ndt.normDist(x)); | |
x = 1.0; | |
System.out.println("f("+x+")="+ndt.normDist(x)); | |
x = 2.0; | |
System.out.println("f("+x+")="+ndt.normDist(x)); | |
x = 3.0; | |
System.out.println("f("+x+")="+ndt.normDist(x)); | |
x = 4.0; | |
System.out.println("f("+x+")="+ndt.normDist(x)); | |
x = -1.0; | |
System.out.println("f("+x+")="+ndt.normDist(x)); | |
x = -2.0; | |
System.out.println("f("+x+")="+ndt.normDist(x)); | |
x = -3.0; | |
System.out.println("f("+x+")="+ndt.normDist(x)); | |
x = -4.0; | |
System.out.println("f("+x+")="+ndt.normDist(x)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment