(50g) Normal Distribution
12-03-2018, 04:20 PM (This post was last modified: 01-26-2019 10:04 PM by John Keith.)
Post: #1
 John Keith Senior Member Posts: 615 Joined: Dec 2013
(50g) Normal Distribution
I have been following these two threads and rather than trolling either with HP 50g programs I am starting this thread of normal distribution programs.

NOTE: The first two programs below should be considered obsolete. They are inaccurate for large values of x as pointed out by Dieter and Albert Chan in following posts. I am leaving them here for illustrative purposes only. The programs in posts 3 and 18 should be used instead.

The function Q(x), the upper tail normal CDF, is implemented in the HP 50 as UTPN. It requires the mean on level 3, the variance on level 2, and x on level 1. Note that the HP Prime implements P(x), the lower-tail CDF as NORMALD_CDF. Either function can be obtained from the other by subtracting the value from 1 as detailed in the above linked threads. For example, the lower-tail normal CDF would simply (but inaccuratly) be
Code:
 \<< UTPN 1. SWAP - \>>

The normal PDF Z(x), which is implemented on the Prime as NORMALD, is not built in to the HP 50. It can be easily (but inaccurately) calculated with the following program:
Code:
 \<< UNROT 2. * UNROT - SQ OVER / NEG EXP SWAP 3.14159265359 * \v/ / \>>

UPDATE: Yes the normal PDF is included. It's called NDIST. Sorry to all for the confusion.

Next, a program to generate normally distributed random numbers. This program uses the Marsaglia polar method and returns two random numbers:
Code:
 \<<   WHILE RAND 2. * 1. - RAND 2. * 1. - DUP2 SQ SWAP SQ + DUP 1. \>=   REPEAT DROP2 DROP   END DUP LN -2. * SWAP / \v/ SWAP OVER * UNROT * \>>

Finally, a somewhat useful example program that takes advantage of the fact that the above program returns two random numbers at a time. Given an integer or a list of array dimensions on level 1, the following program returns an array of normally distributed complex numbers. The program requires the above program stored in a variable named 'N2' in an accessible directory:
Code:
 \<< DUPDUP \-> d   \<< TYPE 5. SAME { 1. + \PILIST } IFT # 1d SWAP R\->B     START N2 R\->C     NEXT d \->ARRY   \>> \>>

I believe that all of the above programs will run on the 48g and 49g calculators but they have only been tested on the 50g.
 « Next Oldest | Next Newest »

 Messages In This Thread (50g) Normal Distribution - John Keith - 12-03-2018 04:20 PM RE: (50g) Normal Distribution - Dieter - 12-03-2018, 07:05 PM RE: (50g) Normal Distribution - John Keith - 12-03-2018, 08:45 PM RE: (50g) Normal Distribution - Albert Chan - 12-03-2018, 09:53 PM RE: (50g) Normal Distribution - Dieter - 12-03-2018, 10:18 PM RE: (50g) Normal Distribution - John Keith - 12-03-2018, 10:59 PM RE: (50g) Normal Distribution - John Keith - 12-04-2018, 08:54 PM RE: (50g) Normal Distribution - Dieter - 12-04-2018, 09:48 PM RE: (50g) Normal Distribution - Albert Chan - 12-04-2018, 11:06 PM RE: (50g) Normal Distribution - Dieter - 12-05-2018, 08:49 PM RE: (50g) Normal Distribution - Albert Chan - 12-05-2018, 03:02 PM RE: (50g) Normal Distribution - John Keith - 12-06-2018, 02:58 PM RE: (50g) Normal Distribution - Dieter - 12-06-2018, 11:08 PM RE: (50g) Normal Distribution - John Keith - 12-07-2018, 11:21 PM RE: (50g) Normal Distribution - Albert Chan - 12-06-2018, 08:30 PM RE: (50g) Normal Distribution - Dieter - 12-06-2018, 10:54 PM RE: (50g) Normal Distribution - Albert Chan - 12-06-2018, 11:36 PM RE: (50g) Normal Distribution - John Keith - 12-08-2018, 07:13 PM RE: (50g) Normal Distribution - Albert Chan - 12-15-2018, 03:03 PM RE: (50g) Normal Distribution - Albert Chan - 12-15-2018, 08:26 PM RE: (50g) Normal Distribution - Albert Chan - 12-08-2018, 08:15 PM RE: (50g) Normal Distribution - Dieter - 12-08-2018, 09:18 PM RE: (50g) Normal Distribution - John Keith - 12-08-2018, 09:28 PM RE: (50g) Normal Distribution - John Keith - 01-26-2019, 10:01 PM RE: (50g) Normal Distribution - pier4r - 01-26-2019, 10:12 PM

User(s) browsing this thread: 1 Guest(s)