flatten hist

gaussdev (replaces TGaussDev)


The gaussdev function returns a 1-dimensional array of random numbers distributed according to a Gaussian probability density function. These values are known as "Gaussian Deviates". The larger the number of values created, the more perfectly they will approximate a Gaussian normal distribution. The related gaussdev1 function returns a single gaussian deviate.

Syntax

tbl = gaussdev( nCount )

tbl = gaussdev( nCount, nStdDev )

tbl = gaussdev( nCount, nStdDev, nMean )

bullet.gif    nCount is the number of Gaussian Deviates to create.

bullet.gif    nStdDev is the standard deviation. If omitted, it defaults to 1.0.

bullet.gif    nMean is the mean value. If omitted, it defaults to 0.0.

bullet.gif    tbl is the returned array containing nCount values.

bullet.gif    On failure, nil is returned.

Example

The following script creates 1 million Gaussian random deviates using the CHistogram class and then plots the histogram. The default histogram binning options are using. The automatic binning computes the minimum and maximum of the values and selects the number of bins between, Since these values are automatic, the script must retrieve the histogram binning to create the plot. A quick method for creating a histogram and plotting it uses the histplot function.

y = gaussdev( 1000000 )

-- create 1 million random deviates

H = new_histogram()

-- create a Histogram object

h = H:Calc( y )

-- compute the histogram

nCount = H:GetBinCount()

-- separate the 3 parameters for clarity

nMin = H:GetMin()+H:GetBinWidth()/2

 

nStep = H:GetBinWidth()

 

x = series( nCount, nMin, nStep )

-- create a series for the histgram x axis

connect( x, h )

-- plot the histogram as a connected plot

H:delete()

 

Below is the result of running this script. The plot uses default labels as they were not specified by the plot function call.

Related Topics

Table and Array Functions

gaussdev1

random

series

CStats class

 

 


Mira Pro x64 Script User's Guide, v.8.73 Copyright Ⓒ 2024 Mirametrics, Inc. All Rights Reserved.