Showing posts with label routines. Show all posts
Showing posts with label routines. Show all posts

Sunday, February 4, 2024

Some RPN Routines: Including Maximum and Minimum of Two Numbers

Some RPN Routines:  Including Maximum and Minimum of Two Numbers



Here are some RPN routines that hopefully you find helpful.   I am assuming that the values are stored in memory registers before calculation and a general four-level stack is used (HP 11C, 12C, 15C, 42S, 32S, 32SII, DM41X, DM32, DM42, DM15, WP34, etc.).  



(a + b + c) × (a + b - c)


Assume that: 

Memory register 1 = a

Memory register 2 = b

Memory register 3 = c

(Your memory registers may have different names or labels)



If recall arithmetic is allowed:


RCL 3

RCL 1

RCL+ 2

+

LST x

RCL- 3

×


(LST x = LAST x)


If recall arithmetic isn't available:


RCL 3

RCL 1

RCL 2

+

+

LST x

RCL 3

-

×



Example:  a= 10, b = 2, c = 7.   Result:  95



 (s + a) × (s + b) × (s + c)


Assume that: 

Memory register 1 = a

Memory register 2 = b

Memory register 3 = c

Memory register 4 = s

(Your memory registers may have different names or labels)


If recall arithmetic is allowed:


RCL 4

ENTER

ENTER

ENTER

RCL+ 1

x<>y

RCL+ 2

×

x<>y

RCL+ 3

×


If recall arithmetic isn't available:


RCL 4

ENTER

ENTER

ENTER

RCL 1

+

x<>y

RCL 2

+

×

x<>y

RCL 3

+

×


Example:  a = 4, b = 8, c = 2, s = 3.   Result:  385



 (s - a) × (s - b) × (s - c)


Assume that: 

Memory register 1 = a

Memory register 2 = b

Memory register 3 = c

Memory register 4 = s

(Your memory registers may have different names or labels)


If recall arithmetic is allowed:


RCL 4

ENTER

ENTER

ENTER

RCL- 1

x<>y

RCL- 2

×

x<>y

RCL- 3

×


If recall arithmetic isn't available:


RCL 4

ENTER

ENTER

ENTER

RCL 1

-

x<>y

RCL 2

-

×

x<>y

RCL 3

-

×


Example:  a = 8, b = 10, c = 3, s = 24.   Result:  4,704



The Maximum and Minimum of the X and Y Stacks



In a program, we can arrange the stack to show the maximum and minimum between two numbers as follows:



Maximum on the X Stack, Minimum on the Y Stack:


...

x≤y   

x<>y

...


If the value of x is less than or equal to y, swap the stack values.  Otherwise, leave the stack as is.



Minimum on the X Stack, Maximum on the X Stack:


HP 12C, HP 11C, HP 10C, and the HP 41C/DM41 family, due to the lack of the  x≥y command:


... 

x≤y

x<>y

x<>y

...


Same routine as the maximum routine, except an extra swap command is placed.



All others:


... 

x≥y

x<>y

...


x≥y is TEST 9 on the HP 15C.  


If the value of x is greater than or equal to y, swap the stack values.  Otherwise, leave the stack as is.

Of course, if your calculator has the maximum (MAX) and minimum (MIN) functions, by all means, use them.  



Eddie


All original content copyright, © 2011-2024.  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. 


Thursday, April 11, 2019

Quickie RPN Routines: HP 42S, DM42, Free 42

Quickie RPN Routines: HP 42S, DM42, Free 42

X, Y refer to their respective stacks and their values

1 + 1 /( 3^(2*X)) + 1/(5^(2*X))

Routine A:
(Labels are omitted for these exercises)

2
*
ENTER
ENTER
3
X <> Y
Y  ↑X
1 / X
X <> Y

X <> Y
Y ↑ X
1 / X
+
1
+
END

Routine B:

2
*
+ / -
3
X <> Y
Y ↑ X
LAST X
5
X <> Y
Y ↑ X
+
1
+
END

Examples:
X:  2.0000,  Result: 1.0139
X:  3.1666,  Result: 1.0010


(X + Y)*(X^2 + Y^2)

Routine A:

ENTER 
X ↑ 2
R ↓
X <> Y
+
LAST X
X ↑ 2
R ↑

*
END

Routine B:

STO ST Z
X ↑ 2
X <> Y
STO + ST Z
X ↑ 2
+
*
END

Examples:
X:  4.0000, Y: 3.0000, Result: 175.0000
X:  2.7000, Y: 3.6000, Result: 127.5750

√(1 + X^2) / √(1 - X^2)

Routine A:

X ↑ 2
1
X <> Y

LAST X
1
+
X <> Y
÷
SQRT
END

Routine B:

X ↑ 2
ENTER
ENTER
1
STO + ST Z
STO - ST Y
R ↓
+ / -
÷
SQRT
END

Examples:
X: 0.5556, Result: 1.3759
X: 0.7278, Result: 1.8035

X / √(X^2 + Y^2)

Routine: 

X ↑ 2 
X <> Y
STO ST Z
X ↑ 2
+
SQRT
÷
END

Examples:
X:  0.5000, Y:  0.7500, Result: 0.5547
X:  1.8080, Y:  1.0220, Result: 0.8705

(X + Y) / (X * Y)

Routine  A:

STO ST Z
X <> Y
STO + ST Z
*
÷
END

Routine B:

ENTER 
R ↓
X <> Y
+
LAST X
R ↑

÷
END

Examples:
X:  5.0000, Y: 4.0000, Result:  0.4500
X:  2.9505, Y: 3.8181, Result:  0.6008

X^Y + Y^X

Routine A:

ENTER
R ↓
X <> Y
Y ↑ X
LAST X
R ↑
Y ↑ X
+
END

Routine B:

ENTER 
R ↓
X <> Y
Y ↑ X
LAST X
R ↑
Y ↑ X
+
END

Examples:
X:  3.9050, Y: 2.7006, Result:  88.0041
X:  4.2650, Y: 4.8750, Result:  2036.6461

Have fun!  See you all next week! 

Eddie

All original content copyright, © 2011-2019.  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.

HP 48G Collection

 HP 48G Collection  Contents:  Intensity of Spherical Light Source  Speed of Light in Dry Air  Pressure of Air  Earth's Gravity a...