RPN with HP 15C & DM32: Solving Simple Systems
Welcome to another edition of RPN with HP 15C & DM32.
Many Approaches to a Solving Problems
This blog covers two ways to solve the simple linear system of two equations:
x + y = a
x – y = b
In matrix form:
[ [ 1, 1 ] [ 1, - 1] ] * [ [ x ] [ y ] ] = [ [ a ] [ b ]
The inverse of the coefficient matrix [ [ 1, 1 ] [ 1, - 1] ]:
[ [ 1, 1 ] [ 1, - 1] ] ^-1 = [ [ 0.5, 0.5 ] [ -0.5, 0.5 ] ]
[ [ x ] [ y ] ] = [ [ 0.5, 0.5 ] [ -0.5, 0.5 ] ] * [ [ a ] [ b ] ]
The solution to the system is:
x = (a + b) / 2
y = (a – b) / 2
As far as keying the solutions in the calculator, we can address this two ways. The first, and probably the easier method, is to use memory registers. The second is to use stack operations such as swap (x<>y), roll up (R↑), roll down (R↓), enter (ENTER) as duplication, and the Last X function (LST x). Both the HP 15C and DM32 use a four-level stack.
The Memory Register Approach
Start with the stack as follows:
Y: a
X: b
The results are presented as:
Y: y
X: x
Memory Registers used:
HP 15C: R1 = a, R2 = b
DM32: A, B
HP 15C Code:
001 |
42, 21, 11 |
LBL A |
002 |
44, 2 |
STO 2 |
003 |
34 |
X<>Y |
004 |
44, 1 |
STO 1 |
005 |
30 |
- |
006 |
16 |
CHS |
007 |
2 |
2 |
008 |
10 |
÷ |
009 |
45, 2 |
RCL 2 |
010 |
45, 40, 1 |
RCL + 1 |
011 |
2 |
2 |
012 |
10 |
÷ |
013 |
43, 32 |
RTN |
DM32 Code (31 bytes):
T01 LBL T
T02 STO B
T03 x<>y
T04 STO A
T05 -
T06 +/-
T07 2
T08 ÷
T09 RCL B
T10 RCL + A
T11 2
T12 ÷
T13 RTN
The Stack Approach
Start with the stack as follows:
Y: a
X: b
The results are presented as:
T : original contents of the z stack
Z: original contents of the z stack
Y: y
X: x
This time no memory registers are used
HP 15C Code:
001 |
42, 21, 12 |
LBL B |
002 |
40 |
+ |
003 |
43, 36 |
LST x |
004 |
2 |
2 |
005 |
20 |
× |
006 |
34 |
X<>Y |
007 |
36 |
ENTER |
008 |
33 |
R↓ |
009 |
30 |
- |
010 |
16 |
CHS |
011 |
2 |
2 |
012 |
10 |
÷ |
013 |
43, 33 |
R↑ |
014 |
2 |
2 |
015 |
10 |
÷ |
016 |
43, 32 |
RTN |
DM32 Code (24 bytes):
S01 LBL S
S02 +
S03 LAST x
S04 2
S05 ×
S06 x<>y
S07 ENTER
S08 R↓
S09 -
S10 +/-
S11 2
S12 ÷
S13 R↑
S14 2
S15 ÷
S16 RTN
Examples
Example 1:
x + y = 32
x – y = 16
32 ENTER 16 (run program)
Results: y = 8, x = 24
Example 2:
x + y = 9
x – y = -8
Results: y = 8.5, x = 0.5
Until next time,
Eddie
All original content copyright, © 2011-2025. 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.