Home
|
Course Outline
|
Lectures
|
Homework
|
Files
This distribution is named for Johann Carl Friedrich Gauss. The Gaussian distribution should be familiar from analysis of experimental errors, which are usually Gaussian distributed about a mean value with a standard deviation that one uses to plot "error bars" on experimental data points.![]()
The Gaussian distribution is very important because of the "Central Limit Theorem" of statistics. This theorem applies to random variables with almost any distribution! The theorem states that the averages of sufficiently large numbers of independently chosen random variables is Gaussian distributed, regardless of the shape of the underlying distribution!
The following applet illustrates this relationship by plottin the Poisson and Gaussian distributions with equal mean values and standard deviations:
The Poisson distribution is plotted both as a histogram for integer n, and as an analytic continuation using Euler's Gamma function:
with the Gamma function computed using comphys.numerics.SpecialFunctions.gamma method. This applet is generated by PoissonGaussian.java:![]()
// PoissonGaussian.java
import comphys.*;
import comphys.graphics.*;
import comphys.numerics.*;
public class PoissonGaussian extends Picture {
double m = 1; // mean value
double poisson (double x) {
double xFactorial = SpecialFunctions.gamma(x + 1);
return Math.pow(m, x) * Math.exp(-m) / xFactorial;
}
double gaussian (double x) {
double x0 = m; // center at mean value
double sigma = Math.sqrt(m);
double factor = 1 / sigma / Math.sqrt(2 * Math.PI);
double exponent = (x - x0) / sigma;
exponent *= - exponent / 2;
return factor * Math.exp(exponent);
}
double xMin = 0;
double xMax = 5;
double yMin = 0;
double yMax = 0.5;
int points = 100;
void findMax () {
yMax = 0;
for (int i = 0; i < 100; i++) {
double x = xMin + i * (xMax - xMin) / points;
double y = poisson(x);
if (y > yMax)
yMax = y;
y = gaussian(x);
if (y > yMax)
yMax = y;
}
}
class Graph extends Plot {
Graph () {
setSize(400, 400);
setBackground("white");
}
public void paint () {
clear();
findMax();
setColor("black");
drawAxes(xMin, xMax, yMin, 1.2 * yMax);
plotString(" y_max = " + Easy.format(yMax, 4), xMin, 1.01 * yMax);
setColor("red");
double x = (int) xMin;
double yOld = poisson(x);
while (x <= (int) xMax) {
double x1 = x - 0.5;
if (x1 < xMin)
x1 = xMin;
double x2 = x + 0.5;
if (x2 > xMax)
x2 = xMax;
double y = poisson(x);
plotLine(x1, yOld, x1, y);
plotLine(x1, y, x2, y);
x += 1;
yOld = y;
}
plotString("____ Poisson", xMin, 1.21 * yMax);
setColor("pink");
x = xMin;
double dx = (xMax - xMin) / points;
yOld = poisson(x);
for (int i = 0; i < points; i++) {
x += dx;
double y = poisson(x);
plotLine(x, y, x - dx, yOld);
yOld = y;
}
setColor("blue");
x = xMin;
yOld = gaussian(x);
for (int i = 0; i < points; i++) {
x += dx;
double y = gaussian(x);
plotLine(x, y, x - dx, yOld);
yOld = y;
}
x = xMin + 0.6 * (xMax - xMin);
plotString("____ Gaussian", xMin + x, 1.21 * yMax);
plotString("sigma = " + Easy.format(Math.sqrt(m), 4), x, 1.1*yMax);
}
}
Graph graph;
Reader mReader, x0Reader, xMinReader, xMaxReader;
public void init () {
add(graph = new Graph());
add(xMinReader = new Reader("x min", xMin, 4));
add(xMaxReader = new Reader("x max", xMax, 4));
add(mReader = new Reader("", m, 4));
addControlPanel();
}
public void draw () {
graph.repaint();
}
public void erase () {
}
public void reset () {
m = mReader.readDouble();
xMin = xMinReader.readDouble();
xMax = xMaxReader.readDouble();
graph.repaint();
}
public static void main (String[] args) {
PoissonGaussian pg = new PoissonGaussian();
pg.frame("Poisson and Gaussian distributions", 430, 530);
}
}