Last active
September 3, 2018 13:32
-
-
Save pandanote-info/cf3d004aff110129d6fb8ac631f814cc to your computer and use it in GitHub Desktop.
累積分布関数を計算するための関数及びテスト用のコード。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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