Showing posts with label erf. Show all posts
Showing posts with label erf. Show all posts

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. 


Saturday, July 15, 2023

Casio fx-3900PV: Program Bank

Casio fx-3900PV:  Program Bank



Here are a few programs for the Casio fx-3900Pv.  These programs should also work on the fx-3600P/fx-180P series (as long as the number of steps is less than 38) except that we can review and edit the steps on the fx-3900Pv.   See my review of the fx-3900Pv here:  


http://edspi31415.blogspot.com/2023/05/retro-review-casio-fx-3900pv.html



Error Function


The program allows the you to calculate the error function:


erf(b) = ∫( 2 * e^(-x²) ÷ √θ dx, x = 0, x = b)


Code:


001   Min

002   MR

003   x²

004   +/-

005   eˣ

006   ×

007   2

008   ÷

009   π

010   √

011   =



To calculate the erf(b):  run integral mode (Mode 1).  Select the program, enter n to get 2^n divisions by pressing [SHIFT] [RUN].   Next, enter 0 [RUN], then b [RUN].


Examples:  n = 6,  (2^6 = 64 divisions)


erf(1.5):

a = 0,  b = 1.5,  Result:  9.661051 * 10^-1


erf(0.4):

a = 0, b = 0.4,  Result:  4.28392 * 10^-1


erf(3.9):

a = 0, b = 3.9,  Result:  9.9999997 * 10^-1




Range and Height of a No-Air Projectile


R = v^2 * sin(2 * θ) ÷ g


H = v^2 * sin^2 θ ÷ (2 * g)


where:

R = range of the projectile (m)

H = maximum height of the projectile (m)

v = initial velocity (m/s)

θ = angle in degrees

g = Earth's gravity = 9.80665 m/s^2


Inputs:

K1 = v

K2 = θ


Outputs:

K3 = R

K4 = H


Used:

K5 = g


Code:


001   DEG  ( MODE 4 )

002   9

003   .

004   8

005   0

006   6

007   6

008   5

009   Kin 5

010   Kout 1

011   x²

012   ÷

013   Kout 5

014   ×

015   (

016   2

017   ×

018   Kout 2

019   )

020   SIN

021   =

022   Kin 3

023   HLT

024   Kout 1

025   x²

026   ×

027   Kout 2

028   SIN

029   x²

030   ÷

031   2

032   ÷

033   Kout 5

034   =

035   Kout 4


Examples:


Inputs:  K1 = 11.9 m/s,  K2 = 40°

Outputs:

R = 14.22082219 m

H = 2.98317166312 m


Inputs:  K1 = 11.9 m/s,  K2 = 60°

Outputs:

R = 12.0558115 m

H = 5.415075484 m

   


Magnitude and Phase of a LCR Series Circuit


Z = √(R² + (w * L - 1 ÷ (w * C))² )


θ = arctan((w * L - 1 ÷ (w * C)) ÷ R)


where:

Z = magnitude (Ω)

θ = phase angle (degrees)

R = resistance (Ω)

L = inductance (H)

C = capacitance (F)

w = angular frequency, where w = 2 * π * f

f = frequency


Inputs:  R, f, C, L

M = f  

K2 = L

K3 = R

K4 = C


Outputs:

K1 = w

K5 = Z

K6 = θ


Note that the source (see Source section below) omitted the square root in the formula for Z.  The above formula is correct.


Code:


001   DEG    (Mode 4)

002   MR

003   Kin 1

004   2

005   Kin× 1   (shown as K×1)

006   π

007   Kin× 1    (shown as K×1)

008   Kout 1

009   ×

010   Kout 2

011   -

012   (

013   Kout 1

014   ×

015   Kout 4

016   )

017   1/x

018   =

019   Kin 6

020   Kout 3

021   x²

022   +

023   Kout 6

024   x²

025   =

026   √

027   Kin 5

028   HLT

029   (

030   Kout 6

031   ÷

032   Kout 3

033   )

034   tan⁻¹

035   =

036   Kin 6



Example:


Inputs:

f = 100 Hz,  [ Min ]

L = 4 * 10^-3 H  (store in K2)

R = 6300 Ω  (store in K3)

C =  5 * 10^-6 F  (store in K4)

Outputs:

Z = 6307.909915 Ω  (K5)

θ = -2.869631956° (K6)



Quadratic Equations:  Real Roots


Solve the equation: 


x^2 + K1 * x + K2 = 0


The roots are:


x = (-K1 ± √(K1^2 - 4 * K2)) ÷ 2


Inputs:

K1 = coefficient of x

K2 = constant


Outputs:

K4 = root 1

K5 = root 2


Used:  K3 = √(K1^2 - 4 * K2)


Code:


001    (

002    Kout 1

003    x²

004    -

005    4    

006    ×

007    Kout 2

008    )

009    √

010    Kin 3

011    (

012    Kout 3

013    +/-

014    -

015    Kout 1

016    )

017    ÷

018    2

019    =

020    Kin 4

021    HLT

022    +

023    Kout 3

024    =

025    Kin 5



Example:


Solve x^2 - 19 * x + 10 = 0

Inputs:

K1 = -19

K2 = 90

Outputs:  9, 10



Source 

(for Range and Height of a No-Air Projectile and Magnitude and Phase of a LCR Series Circuit):


Rosenstein, Morton.   Computing With the Scientific Calculator.  Casio.  1986



Enjoy,


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. 


Saturday, July 9, 2016

HP 42S Programming Part I: Matrix Column Sum, GCD, Error Function

HP 42S Programming Part I:  Matrix Column Sum, GCD, Error Function

Continuing with calculators from the 1980s, this series will present one of the most beloved scientific calculators and one of the most sought after: the Hewlett Packard HP 42S from the late 1980s.  If you want one, you might want to save up because HP 42S calculators are valuable, and often cost over $100.

It is one of my most favorite calculators of all time. 

Free42

However, you can use an emulator for the HP 42S for free, check out the Free42 by Thomas Oakken.  It is a rewrite of the HP 42S code and the emulator is available on many platforms including Widows, Mac, iOS, and Android.  Link:  http://thomasokken.com/free42/   

Oakken accepts donations.





Part III hopefully to come next week.  

As usual, anything that comes after the double-backslash is a comment only.

HP 42S: Column Sums of a Matrix

This could potentially had been a medium to long sized programs involving loops, but thanks to the powerful function RSUM (found in CATALOG-FUNC or executed by XEQ RSUM) this program will be quite short.  RSUM is the row sum function, or the sum of each row of a matrix.

Just put a matrix on the stack and run CSUM.  When the program is finished, press [shift] [ 9 ] (MATRIX), {EDIT} to see the sums.

00 {12-Byte Prgm}
01 LBL “CSUM”
02 TRANS \\ transpose
03 RSUM
04 END

Test:  MAT1 = [ [4, 3, 1], [5, 8, 2], [7, 6, 3]]
Result:  [16, 17, 6]

HP 42S:  GCD (Greatest Common Divisor) by Euclid Division

Enter the two integers on the Y stack and X stack.  Order doesn’t matter.

00 {42-Byte Prgm}
01 LBL “GCD”
02 X<Y?
03 X<>Y
04 STO 01  \\ store maximum in R01
05 X<>Y
06 STO 00  \\ store minimum in R00
07 LBL 00 \\ main loop
08 RCL 01
09 ENTER
10 RCL÷ 00
11 IP
12 RCL* 00
13 –
14 X=0?  \\ is max – IP(min/max)*min = 0?
15 GTO 01
16 X<>Y
17 STO 01
18 X<>Y
19 STO 00
20 GTO 00
21 LBL 01 \\ display GCD
22 RCL 00
23 “GCD:”
24 ARCL ST X
25 AVIEW
26 END


Test:   Find the GCD of 485 and 175.
485 [ENTER] 175 [XEQ] {GCD}   Result:  5
Alternatively:
175 [ENTER] 485 [XEQ] {GCD}   Result:  5


HP 42S:  Error (erf) Function


ERF(X) = ∫ 2/√π * (e^(-T^2)) dT, from T = 0 to T = x

Integrand:
00 {22-Byte Prgm}
01 LBL “ERF”
02 MVAR “T”
03 RCL “T”
04 X^2
05 +/-
06 E^X
07 2
08 *
09 PI
10 SQRT
11 ÷
12 END

Instructions:

Press [(shift)] [ 8 ] (∫ f(x) )
Choose ERF at the “Select ∫f(x) Program”
Select T at Set Vars; Select ∫var
Store 0 in LLIM, X in ULIM, a suitable accuracy factor (10^-n) in ACC
Press the ∫ soft key.

Test: erf(1.2) with ACC of 1E-6  (LLIM = 0, ULIM = 1.2) 
Result:  0.9103


 This blog is property of Edward Shore, 2016.

Wednesday, July 6, 2016

TI-55 III Programs Part II: Impedance of a Series RLC Circuit, Quadratic Equation, Error Function

TI-55 III Programs Part II: Impedance of a Series RLC Circuit, Quadratic Equation, Error Function

On to Part II!



TI-55 III:  Impedance of Series RLC Circuit

The impedance of a series RLC circuit in Ω (ohms) is:

Z = √(R^2 + (2*π*f*L – 1/(2*π*f*C))^2)

Where:
R = resistance of the resistor in ohms (Ω)
L = inductance of the inductor in Henrys (H)
C = capacitance of the capacitor in Farads (F)
f = resonance frequency in Hertz (Hz)
XL = 2*π*f*L
XC = 1/(2*π*f*C)

Program:
Partitions allowed: 1-4
STEP
CODE
KEY
COMMENT
00
65
*
Start with f
01
02
2

02
65
*

03
91
π

04
95
=

05
61
STO

06
00
0
Store 2πf in R0
07
65
*

08
12
R/S
Prompt for L
09
75
-

10
53
(

11
71
RCL

12
00
0

13
65
*

14
12
R/S
Prompt for C
15
54
)

16
17
1/x

18
18
X^2

19
85
+

20
12
R/S
Prompt for R
21
18
X^2

22
95
=

23
13

24
41
INV

25
47
Eng
Cancel Eng Notation
26
12
R/S
Display Z

Input:  f [RST] [R/S], L [R/S], C [R/S], R [R/S]
Result:  Z

Test:
f = 60 Hz
L = 0.25 H
C = 16 * 10^-6 F
R = 150 Ω

Result:  166.18600 Ω

TI-55 III: Quadratic Equation

This program find the real roots of the equation:
X^2 + B*X + C = 0

Where:
D = B^2 – 4*C
If D ≥ 0, then continue the program since it will find the real roots.  Otherwise, stop since the roots are complex and is beyond the scope of this program.  The two roots are:
X1 = (-B + √D)/2
X2 = (-B - √D)/2

Program:
Partitions Allowed: 3
STEP
CODE
KEY
COMMENT
00
71
RCL
Calculate Discriminant
01
00
0

02
18
X^2

03
75
-

04
04
4

05
65
*

06
71
RCL

07
01
1

08
95
=

09
12
R/S
Display Discriminant
10
13

11
61
STO

12
02
2

13
75
-

14
71
RCL

15
00
0

16
95
=

17
55
÷

18
02
2

19
95
=

20
12
R/S
Display X1
21
53
(

22
71
RCL

23
00
0

24
85
+

25
71
RCL

26
02
2

27
54
)

28
94
+/-

29
55
÷

30
02
2

31
95
=

32
12
R/S
Display X2

Input:  B [STO] 0, C [STO] 1, [RST] [R/S]
Results:  Discriminant [R/S], root 1 [R/S], root 2

Test:  Solve X^2 + 0.05*X – 1 = 0
Input:  0.05 [STO] 0, 1 [+/-] [STO] 1 [RST] [R/S]
Results:  Discriminant = 4.0025  (It is non-negative, continue) [R/S]
X1 ≈ 0.9753125  [R/S]
X2 ≈ -1.0253125

TI-55 III: Gaussian Error Function

The error function is defined as:
erf(x) = ∫( 2*e^(-t^2)/√π dt, from t = 0 to t = x)

This program illustrates the integration function [ ∫ dx ] on the TI-55 III.

Program:
Prepare by pressing [2nd] [LRN] (Part) 3.  Integration needs a minimum of 3 memory registers.  That means, f(x) can take a maximum of 40 steps.
STEP
CODE
KEY
COMMENT
00
18
X^2
Integrand
01
94
+/-

02
41
INV

03
44
ln x
[INV] [ln x]: e^x (EXP)
04
65
*

05
02
2

06
55
÷

07
91
π

08
13

09
95
=

10
12
R/S

11
22
RST
End f(x) with =,R/S,RST

Input:  0 [STO] 1 (lower limit), x [STO] 2 (upper limit), [ ∫ dx ] n (number of partitions) [R/S]
Result: erf(x)
Test 1: erf(1.2) ≈ 0.910314. I use 12 partitions.
Input:  0 [STO] 1, 1.2 [STO] 2, [ ∫ dx ] 12 [ R/S ]
Result:  0.910314

Test 2:  erf(0.9) ≈ 0.7969082.   Store 0 in R0, 0.9 in R1.  12 partitions are used.

 Eddie

This blog is property of Edward Shore, 2016.



HP 32SII: Volume of a Square Frustum (Three Approaches in RPN)

HP 32SII: Volume of a Square Frustum (Three Approaches in RPN ) The volume of a square frustum is: v = height ÷ ...