Normal
Distribution Example (Screen Shot)

This screen shot shows a chart of normal distribution Y values as a function
of X values. The spBasic program below is used to generate the chart from
information provided by the user in cells b3 to b6. The program uses the
Excel SQRT, EXP, AVERAGE, and STDEV functions.
The screen shot below shows the spBasic Edit Form for the 'NormalDistribution' program.

You can copy the listing below and insert it into your Edit Form. Insert the variables into a worksheet column. This program is also included in the 'C:\Program Files\spBasic\Examples\' directory.
NOTE: Install the Analysis Toolpak AddIn to use the advanced Excel
functions.
// variables
sigma
mu
startX
deltaX
i
x
End
// ----- NormalDistribution -----
// NOTE: anything after the characters "//" are comments
and
// are
ignored by the program
// sigma, mu, startX, deltaX are set by the user
x = startX
clear c2:d100
// -- loop over 70 data points --
for i = 1 to 70
c<<i+1>> = x
// -- set column D to the normal distribution function value
--
d<<i+1>>=(1/(sigma*SQRT(2*PI())))*EXP(-((x - mu)^2)/(2*(sigma)^2))
// -- increment x --
x = x + deltaX
next
// -- compute average and standard deviation of Y values --
e10 = " Average Y = " & fixed(Average(d2:d71),4,true)
e11 = " Standard Deviation Y = " & fixed(STDEV(d2:d71),4,true)
End
|