Skip to content

Instantly share code, notes, and snippets.

@pandanote-info
Last active September 3, 2018 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pandanote-info/cf3d004aff110129d6fb8ac631f814cc to your computer and use it in GitHub Desktop.
Save pandanote-info/cf3d004aff110129d6fb8ac631f814cc to your computer and use it in GitHub Desktop.
累積分布関数を計算するための関数及びテスト用のコード。
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