
NCL Home >
Documentation >
Functions >
General applied math,
Statistics
genNormalDist
Generates a normal distribution.
Prototype
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" ; This library is automatically loaded ; from NCL V6.2.0 onward. ; No need for user to explicitly load. function genNormalDist ( xAve [1] : numeric, xStd [1] : numeric, opt [1] : logical ) return_val [*] : float or double
Arguments
xAveA scalar specifying the mean of the distribution.
xStdA scalar specifying the standard deviation of the distribution.
optAttributes may be associated with this variable. The attributes will alter the default behavior of the genNormalDist.
Setting opt=False will result in default values being used.
Setting opt=True will activate use of the options.
- spn - Change the span of the generated distribution. The default is 3.0 standard deviations. This means that 99.7% of all values will fall within this range.
- npts - The number of points to be generated. The default is 101. It is not necessary that an odd number be used. Using an odd number results in a return array that will contain the central value. NOTE: Beginning with 6.2.0, the attribute N will be a synonym for npts
Return value
A one-dimensional array of size=101 or, if the N attribute is set to size=N. The following attributes will be associated with the return variable.
- x - the generated abscissa values.
Description
Uses the standard formula:
normal(xAve,xStd) = [1/(xStd*sqrt(2*pi)]*exp[-(0.5*(x-xAve)^2/xStd^2)where
spn = 3.0 ; default is 3.0 standard deviations x = fspan( (xAve-spn*xStd), (xAve+spn*xStd), N)
See Also
Examples
Example 1
Using default settings:
nd = genNormalDist(100,10, False) print(sprintf("%5.2f", nd@x)+" "+sprintf("%9.6f", nd)+" "+sprintf("%9.6f", nd@xsd) )The print(...) yields:
Variable: nd Type: float Total Size: 404 bytes 101 values Number of Dimensions: 1 Dimensions and sizes: [101] Coordinates: Number Of Attributes: 3 long_name : Normal Distribution x : ARRAY of 101 elements xsd : ARRAY of 101 elements nd@x nd nd@xsd (0) 70.00 0.000443 -3.000000 (1) 70.60 0.000530 -2.940000 (2) 71.20 0.000631 -2.880000 (3) 71.80 0.000748 -2.820000 (4) 72.40 0.000885 -2.760000 (5) 73.00 0.001042 -2.700000 [snip] (47) 98.20 0.039253 -0.180000 (48) 98.80 0.039608 -0.120000 (49) 99.40 0.039822 -0.060000 (50) 100.00 0.039894 0.000000 (51) 100.60 0.039822 0.060000 (52) 101.20 0.039608 0.120000 (53) 101.80 0.039253 0.180000 [snip] (95) 127.00 0.001042 2.700000 (96) 127.60 0.000885 2.760001 (97) 128.20 0.000748 2.820000 (98) 128.80 0.000631 2.880000 (99) 129.40 0.000530 2.939999 (100) 130.00 0.000443 3.000000A simple x-y plot could be generated by using the returned x attribute values as the abscissa values and the "nd" values as ordinate values.
wks = gsn_open_wks ("x11","PDFX") res = True res@gsnCenterString = "default 101 values" plot = gsn_csm_xy (wks, nd@x, nd, res)
Example 2:
Specify that 51 values be generated. The default is to generate 101 values.
opt = True ;opt@npts = 51 opt@N = 51 ; This will be allowed from 6.2.0 onward opt@opt_span = 5 ; number if standard deviation to span. default is 3.0 zNorm = genNormalDist(zave, zstd, opt)