LoginSignup
0
0

正規分布(ガウス分布)曲線

Posted at

はじめに

 Processingには正規分布に基づいた乱数生成関数randomGaussian()がある。しかし、曲線をパッと作る機能はなかったので、とりあえず用意した。

Gaussian.png

Processing
size(1000, 600);
noFill();
float sig = 1;
float u = 0;
translate(500, 500);
scale(100);
strokeWeight(0.01);

beginShape();
for (float x = -5; x < 5; x+=0.01) {
  float f = 1f/sqrt(2f*PI)/sig*exp(-(x-u)*(x-u)/2f/sig/sig);
  f*=10;
  curveVertex(x, -f);
}
endShape();

※この画像のグラフは、横は-5〜5、縦は-0.5〜0.1となっている。つまり、かなり、上下方向に拡大されている。

式を簡略化した場合。

Processing
size(1000, 600);
noFill();
translate(500, 500);
scale(100);
strokeWeight(0.01);

beginShape();
for (float x = -5; x < 5; x+=0.01) {
  float f = 4*exp(-x*x/2f);
  curveVertex(x, -f);
}
endShape();

さらに、計算量少なそうな式に変更。

Processing
size(1000, 600);
noFill();
translate(500, 500);
scale(100);
strokeWeight(0.01);

beginShape();
for (float x = -5; x < 5; x+=0.01) {
  float f = 4/(1+x*x);
  curveVertex(x, -f);
}
endShape();

a.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0