Gaussian function

This is the curve of the normal distribution: e-x2/2. It's tricky to calculate because numbers get so large (small) in the tail. This version works to maybe 4 sigma, before overflowing.

I use it to validate the normal distribution of random numbers. A display of this function is superimposed on them, and even grows along with them. It's a fun, dynamic display.

This code in block 1216 is loaded into node 613. It talks to node 713 which provides a run-length display in green.

Arithmetic

The arithmetic required for this calculation is educational. I'm using 11-bit fractions which require extra shifting.

*.

/.

Function

The approximation is from Hastings' Approximations for Digital Computers, Princeton University Press, 1955, Sheet 27. An oldy but goody reference.

The approximation is 1 divided by a cubic polynomial in x2. I don't care about normalizing the area, so I normalize the fraction to an 11-bit 1. With x=4, (x2)3 is a really large number, so I divide x2 by 2 to help (that screws up the standard-deviation). I only use 2 decimal digits in the coefficients for the same reason. A different application would justify more work.

e-x2

The cryptic name is intended to suggest the funtion.

go