Post Reply 
(15C)(DM15) - PDF/CDF and Inverse of a Normal Distribution
11-24-2021, 03:37 PM
Post: #1
(15C)(DM15) - PDF/CDF and Inverse of a Normal Distribution
Hello!

This is my second program I wrote for my new DM15.

It calculates the probability density function (PDF), the cumulative distribution function (CDF) and their inverse functions (!) of a standardized normal function.

Call it with the argument (Y) and the desired function number (X). The function number is 1 for the PDF, 2 for its inverse, 3 for the CDF and 4 for its inverse.

To calculate the CDF I used some approximating function rather than integrating the PDF, which offers a accuracy of at least 2 digits (error < 1%) and is much faster.

The label to call is D (distribution).

Examples:
* 0 (Y) and 1 (X) calculates PDF(0)=0.39
* 0.1 (Y) and 2 (X) calculates 1.66 (the positive solution) where the PDF is 0.1
* 1 (Y) and 3 (X) calculates CDF(1)=0.84
* 0.95 (Y) and 4 (X) calculates 1.64 where CDF(1.64)=0.95

The Code:

Code:

# ------------------------------------------------------------------------------
#T:Normal Distribution
#D:Calculates PDF, PDFinverse, CDF and CDFinverse of a standardized normal distribution.
#D:
#D:INPUT:
#D:Y: Argument
#D:X: Function
#D:
#D:FUNCTION:
#D:1: PDF
#D:2: PDFinverse, Argument = 0 ... 1/sqrt(2*pi)
#D:3: CDF
#D:4: CDFinverse, Argument = 0 ...1
#D:
#D:PDF(x) = 1/sqrt(2*PI) * exp(-x*x/2)
#D:
#D:CDF(x) = (integral, [-inf;x]) PDF(z) * dz =(approx)= 1/(1 + exp(-0.07*x*x*x-1.6*x))
#L-4:Distribution (Start Program)
#L10:PDF
#L11:CDF
#L12:Menu entry 2
#L13:Menu entry 3
#L14:Menu entra 4
#RI:Target for SOLVE
# ------------------------------------------------------------------------------

   000 {             } 
   001 {    42 21 14 } f LBL D
   002 {           1 } 1
   003 {    43 30  8 } g TEST x<y
   004 {    22 48  2 } GTO .2
   005 {           0 } 0
   006 {       44 25 } STO I
   007 {       43 33 } g R⬆
   008 {    32 48  0 } GSB .0
   009 {       43 32 } g RTN
   010 { 42 21 48  2 } f LBL .2
   011 {          33 } R⬇
   012 {           2 } 2
   013 {    43 30  8 } g TEST x<y
   014 {    22 48  3 } GTO .3
   015 {          33 } R⬇
   016 {          33 } R⬇
   017 {       44 25 } STO I
   018 {           2 } 2
   019 { 42 10 48  0 } f SOLVE .0
   020 {       43 32 } g RTN
   021 { 42 21 48  3 } f LBL .3
   022 {          33 } R⬇
   023 {           3 } 3
   024 {    43 30  8 } g TEST x<y
   025 {    22 48  4 } GTO .4
   026 {           0 } 0
   027 {       44 25 } STO I
   028 {       43 33 } g R⬆
   029 {    32 48  1 } GSB .1
   030 {       43 32 } g RTN
   031 { 42 21 48  4 } f LBL .4
   032 {          33 } R⬇
   033 {          33 } R⬇
   034 {       44 25 } STO I
   035 {           0 } 0
   036 { 42 10 48  1 } f SOLVE .1
   037 {       43 32 } g RTN
   038 { 42 21 48  0 } f LBL .0
   039 {       43 11 } g x²
   040 {           2 } 2
   041 {          16 } CHS
   042 {          10 } ÷
   043 {          12 } eˣ
   044 {       43 26 } g π
   045 {           2 } 2
   046 {          20 } ×
   047 {          11 } √x̅
   048 {          10 } ÷
   049 {       45 25 } RCL I
   050 {          30 } −
   051 {       43 32 } g RTN
   052 { 42 21 48  1 } f LBL .1
   053 {          36 } ENTER
   054 {          36 } ENTER
   055 {          36 } ENTER
   056 {          20 } ×
   057 {          20 } ×
   058 {          48 } .
   059 {           0 } 0
   060 {           7 } 7
   061 {          16 } CHS
   062 {          20 } ×
   063 {          34 } x↔y
   064 {           1 } 1
   065 {          48 } .
   066 {           6 } 6
   067 {          20 } ×
   068 {          30 } −
   069 {          12 } eˣ
   070 {           1 } 1
   071 {          40 } +
   072 {          15 } 1/x
   073 {       45 25 } RCL I
   074 {          30 } −
   075 {       43 32 } g RTN

# ------------------------------------------------------------------------------

Have fun!

Regards
deetee
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(15C)(DM15) - PDF/CDF and Inverse of a Normal Distribution - deetee - 11-24-2021 03:37 PM



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