Sunday, September 24, 2023

HP 15C: Error Function and Lower Tail Normal Cumulative Function

 HP 15C:   Error Function and Lower Tail Normal Cumulative Function






Formulas Used 



Error Function 


erf(x) = 2 ÷ √π * ∫( e^(-t^2) dt, t = 0 to t = x)




CDF (Cumulative Normal Distribution Function)


CDF(x) = 1 ÷ √(2 * π) * ∫( e^(-t^2) dt, t = -∞ to t = x)


We can use the error function to calculate CDF(x):


0.5 - erf(x), for x < 0


0.5 + erf(x), for x ≥ 0



This program uses the integration function inside the program.  We will need 23 free memory registers to run the program, which will be terminated at the end of program execution.



Labels used:


B:  erf function (error function)

C:  lower tail normal CDF 

4:  function used for integration


(Of course, feel free to use the labels you want, just be mindful to make the appropriate adjustments)




HP 15C Program Code:  Error Function and Lower Tail Normal Cumulative Function


Steps:  35

Bytes:  40



Step # :  Key Code :  Key


001 : 42,21,12:  LBL B

002 :  0  :   0

003 : 34 : x<>y

004 : 42,20, 4 : ∫_x_y 4

005 : 43, 32 : RTN


006 : 42,21,13 : LBL C

007 : 43,30, 2 :  TEST 2 (x<0)

008 : 43, 4, 0 : SF 0

009 : 43, 16 :  ABS

010 : 0   :   0

011 : 34 :  x<>y

012 : 2   :  2

013 : 11 :  √

014 : 10 :  ÷

015 : 42,20, 4 : ∫_y_x 4

016 : 2   :  2

017 : 10 :  ÷

018 : 48 :  .

019 : 5   :  5

020 : 34 :  x<>y

021 : 43, 6, 0 :  F?0

022 : 16  : CHS

023 : 40  :  +

024 : 43, 5, 0 : CF 0

025 : 43, 32 : RTN


026 : 42,21, 4 : LBL 4

027 : 43,11 : x^2

028 : 16 :  CHS

029 : 12 :  e^x

030 :  2  :  2

031 :  20  : ×

032 :  43,26 : π

033 :  11 :  √

034 :  10 :  ÷

035 :  43,32 : RTN




Examples


x = -0.7:  erf (N/A), CDF ≈ 0.2420


x = 0.7:  erf ≈ 0.6778, CDF ≈ 0.7580


x = 1:   erf ≈ 0.8427,  CDF ≈ 0.8413


x = 2.5  erf ≈ 0.9996,  CDF ≈ 0.9938



Eddie



All original content copyright, © 2011-2023.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.