Showing posts with label Swiss Micros. Show all posts
Showing posts with label Swiss Micros. Show all posts

Saturday, February 14, 2026

RPN: Absolute Value Equations with the HP 11C and DM41X

RPN: Absolute Value Equations with the HP 11C and DM41X



Introduction: Solving |z * w + y| = x


Today’s blog focuses on solving the absolute value equation:


|z * w + y| = x


for the variable w, and the values of z, y, and x are given and are on the Classic RPN stack.


For example, in the problem |5 * w + 7| = 2, the stack would be set up as:


t: (anything, it doesn’t matter)

z: 5

y: 7

x: 2


(This is why I set the variable as w instead of the usual x.)


One approach is to use memory registers and other uses only stack operations. Today’s algorithm focuses on the latter.


Caution: In the above equation, x will always be non-negative. The equation will never be valid if x is negative.



The Algebra


Solve for w:

|z * w + y| = x


This leads us to solve the two equations:


(I)

z * w + y = -x

z * w = -x – y

w = -x/z – y/z


Let w- = -x/z – y/z = (-x/z) + (-y/z)


(II)

z * w + y = x

z * w = x – y

w = x/z - y/z


Let w+ = x/z – y/z = (x/z) + (-y/z)


Then:


w- = -x/z – y/z

w- = (-x/z) + (-y/z)

w- = (-x/z) + (-y/z) + (-x/z) + (x/z)

w- = 2 * (-x/z) + (x/z) + (-y/z)

w- = 2 * (-x/z) + w+


RPN Code: HP 11C (adoptable for other RPN calculators)


LBL A

001

42, 21, 11

Program start

R↓

002

33


R↓

003

33


X<>Y

004

34


R↓

005

33


1/x

006

15


×

007

20


LST x

008

43, 36


X<>Y

009

34


R↓

010

33


×

011

20


LST x

012

43, 36


R↑

013

43, 33


X<>Y

014

34


R↓

015

33


X<>Y

016

34


CHS

017

16


X<>Y

018

34


+

019

40


ENTER

020

36


ENTER

021

36


LST x

022

43, 36


-

023

30


LST x

024

43, 36


-

025

30


RTN

026

43, 32

Program end


RPN Code: DM41X (HP 41C series, no module is required)


LBL “ASBEQ”

RDN

RDN

X<>Y

RDN


1/x

×

LAST X

X<>Y

RDN

×

LAST X

R↑

X<>Y


RDN


X<>Y

CHS

X<>Y


+

ENTER

ENTER

LAST X

-

LAST X

-


RTN



Notes:

* RDN is shown as R↓

* To enter R↑, press XEQ, ALPHA, R, SHIFT, ENTER, ALPHA



Subroutines Used


We used several techniques to manipulate the stack. They are presented below:


Rotate stack from X, Y, Z, T to Z, X, Y, T

R↓

R↓

X<>Y

R↓


Source:

Ball, John A. Algorithms for RPN Calculators John Wiley & Sons: New York. 1978. ISBN 0-471-03070-8. pg. 78



Multiply Y and Z by 1/X. Stack: X, Y, Z, T → X, Y/X, Z/X, T


1/x

×

LAST X

X<>Y

R↓

×

LAST X

R↑

X<>Y


Change X, Y to Y+ X, Y – X


+

ENTER

ENTER

LAST X

-

LAST X

-


The resulting stack is:


z

z

y + x

y – x


Doing LAST X, -, twice is effectively subtracting whatever is in L register twice.



Examples


|4 * w – 6| = 5


Stack:

z: 4

y: -6

x: 5


Results:

y: 2.75

x: 0.25


|2 * w + 5| = 3


Stack:

z: 2

y: 5

x: 3


Results:

y: -1

x: -4




Eddie


All original content copyright, © 2011-2026. 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, May 10, 2025

RPN with HP 15C and DM32: Complex Mode

RPN with HP 15C and DM32: Complex Mode



HP 15C Complex Mode


This section also applies to the Swiss Micros DM15 family.


Complex mode is a separate mode for the HP 15C. Complex mode is turned on by setting flag 8. Complex mode is on when there is a “C” indicator in the display.


In complex mode, the stack is expanded. Each stack level now includes a real part and a complex part. What is in the display is always the real part.


Stack T

Real part of T

Imaginary part of T

Stack Z

Real part of Z

Imaginary part of Z

Stack Y

Real part of Y

Imaginary part of Y

Stack X

Real part of X

Imaginary part of X


The great news is that the stack handles up to four complex numbers, one for each of the stack levels.


To display the imaginary part, we have two methods:


Temporary View: Press [ f ] and hold [ COS ] (i) to temporarily view the complex part. The stack remains unaffected.


Switch: Switch the real part and the imaginary part by pressing [ f ] [ - ] (Re<>Im). Doing this switches the real and imaginary parts of the X stack.


For example: X = 9 – 8i


Enter the complex number as such: 9 [ ENTER ] 8 [ CHS ] [ I ] * (see note).

The displays shows 9.

Press [ f ] [ - ] (Re<>Im). The display shows -8 and the X stack now has the complex number X = -8 + 9i.

Press [ f ] [ - ] (Re<>Im) to switch the parts back to the original complex number.


* Note: If complex mode is turned off (no C indicator), using this key sequence sets flag 8, turning on complex mode automatically.


The switching of parts is important, because memory registers can not hold an entire complex number, but it’s separate parts. Thus, we will need two registers, one for the real part and one for the imaginary part.



HP 15C: Leaving Complex Mode


To leave complex mode, clear flag 8 (CF 8). The imaginary parts of the stack are lost.



Angle Mode


In complex mode, the trigonometric functions operate as the angles are always in radian measure regardless of the angle setting. The only functions that recognize the angle setting are the polar/rectangular conversions. To take the cosine and sine of angle that respects the conversion, use the following sequence:


angle [ENTER] 1 [ f ] [ →R ]: X stack: cos(angle), Y stack: sin(angle)



HP 15C - Solving Monic Quadratic Equations


The HP 15C’s solver only works for real numbers, so manual methods and formulas must be used to solve equations for complex numbers.



Z^2 + w1 * Z + w0 = 0


Solution: Z = (w1 ± √(w1^2 – 4 * w0)) / 2

(D = √(w1^2 – 4 * w0), Z+ = (w1 + D) / 2 Z- = Z+ - D)


Store the following:


Complex coefficient w1: Real part in register 4, Imaginary part in register 5

Complex coefficient w2: Real part in register 1, Imaginary part in register 2


The results are stored in the following registers:


Discriminant (D): Real part in register 6, imaginary part in register 3

Complex root Z+: Real part in register .0 (decimal point-0), imaginary party in register 8

Complex root Z-: Real part in register 9, imaginary part in register 7


Code (use any label you want, I use label A for example):


Key

Key Code


Key

Key Code

LBL A

42, 21, 11


RCL 4

45, 4

SF 8

43, 4, 8


RCL 1

45, 1

RCL 4

45, 4


I

42, 25

RCL 1

45, 1


-

30

I

42, 25


2

2

x^2

43, 11


÷

10

RCL 5

45, 5


STO .0

44, .0

RCL 2

45, 2


Re<>Im

42, 30

I

42, 25


STO 8

44, 8

4

4


Re<>Im

42, 30

×

20


R/S

31

-

30


RCL 6

45, 6

11


RCL 3

45, 3

STO 6

44, 6


I

42, 25

Re<>Im

42, 30


-

30

STO 3

44, 3


STO 9

44, 9

Re<>Im

42, 30


Re<>Im

42, 30




STO 7

44, 7




Re<>Im

42, 30




RTN

43, 32



Example:

Z^2 + (4 + i) * Z + (2 - 5i) = 0

w1: 4 STO 4, 1 STO 1

w2: 2 STO 5, 5 CHS STO 2


[ f ] A or [ GSB ] A:

0.11724 [ f ] hold (i) 1.15309 (Z+ ≈ 0.11724 + 1.15309i)

[ R/S ]

-4.11724 [ f ] hold (i) -2.15309 (Z- ≈ -4.11724 – 2.15309i)



DM32 Complex Mode


This section also applies to the HP 32Sii, HP 32S, and the HP 41C/DM41X with the Advantage ROM plugged in. The names of the functions vary.


There is no “separate” complex mode for the DM32, all the functions are access with shifted CMPLX prefix function. The complex number functions available on the DM32 are:


CMPLX+, CMPLX-, CMPLX×, CMPLX÷

CMPLX+/- (change sign, multiply the complex number by -1)

CMPLX1/x, CMPLXe^x, CMPLXLN, CMPLXy^x

CMPLXSIN, CMPLXCOS, CMPLXTAN


The complex functions grabs the values from the four stack levels and uses them as up to two complex numbers:

Z

Imaginary part of T + Zi

T

Real part of T + Zi

Y

Imaginary part of X + Yi

X

Real part of X + Yi


Memory registers can not hold an entire complex number, but it’s separate parts. Thus, we will need two registers, one for the real part and one for the imaginary part.


To enter complex numbers, enter the imaginary part, press [ ENTER ], then enter the real part.



Square Root and Square (√ and x^2)


There is no complex square root or complex square function. We will need some creativity to tackle these functions. Here is just one way we can accomplish this task.


Assume the complex number A + Bi have the real part stored in A and imaginary part stored in B.


Square Root (√):

RCL B

RCL A

0.5

ENTER

Clx

x<>y

CMPLXy^x


Square (x^2):

RCL B

RCL A

RCL B

RCL A

CMPLX×


Angle Mode


In complex mode, the trigonometric functions operate as the angles are always in radian measure regardless of the angle setting. The only functions that recognize the angle setting are the polar/rectangular conversions. To take the cosine and sine of angle that respects the conversion, use the following sequence:


1 [ENTER] angle [ blue shift ] [ →y,x ]: X stack: cos(angle), Y stack: sin(angle)


(HP 32SII late editions: lavender/purple shift)



DM32 - Solving Monic Quadratic Equations


Like the HP 15C, the DM32’s solver only works for real numbers, so manual methods and formulas must be used to solve equations for complex numbers.


Z^2 + w1 * Z + w0 = 0


Solution: Z = (w1 ± √(w1^2 – 4 * w0)) / 2

(D = √(w1^2 – 4 * w0), Z+ = (w1 + D) / 2 Z- = Z+ - D)


Store the following:


Complex coefficient w1: Real part in A, Imaginary part in B

Complex coefficient w2: Real part in C, Imaginary part in D

The program will prompt for A, B, C, and D, in the order of imaginary part, then real part

Z^2 + (Bi + A) * Z + (Di + C) = 0


The results are stored in the following registers:


Discriminant (D): Real part in E, imaginary part in F

Complex root Z+: Real part in R, imaginary party in S

Complex root Z-: Real part in U, imaginary part in V


Code:

A01 LBL A

A24 x<>y

A02 INPUT B

A25 RCL B

A03 INPUT A

A26 RCL A

A04 INPUT D

A27 CMPLX-

A05 INPUT C

A28 2

A06 RCL B

A29 ENTER

A07 RCL A

A30 CLx

A08 RCL B

A31 x<>y

A09 RCL A

A32 CMPLX÷

A10 CMPLX×

A33 STO S

A11 4

A34 x<>y

A12 RCL× D

A35 STO R

A13 4

A36 x<>y

A14 RCL× C

A37 STOP

A15 CMPLX-

A38 RCL F

A16 0.5

A39 RCL E

A17 ENTER

A40 CMPLX-

A18 CLx

A41 STO U

A19 x<>y

A42 x<>y

A20 CMPLXy^x

A43 STO V

A21 STO E

A44 x<>y

A22 x<>y

A45 RTN

A23 STO F




Example:

Z^2 + (4 + i) * Z + (2 - 5i) = 0

[ XEQ ] A

B? 1 [R/S]

A? 4 [R/S]

D? -5 (5 [+/-] ) [R/S]

C? 2 [R/S]


Y: 1.15309, X: 0.11724 (Z+ ≈ 0.11724 + 1.15309i)

[R/S]

Y: -2.15309, X: -4.11724 (Z- ≈ -4.11724 – 2.15309i)




I hope you enjoyed this edition of RPN with HP 15C and DM2,


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.

HP 65 Programs: Triangulation, Percentile, Roots of Unity, Partial Fractions

  HP 65 Programs: Triangulation, Percentile, Roots of Unity, Partial Fractions Triangulation (done with HP-65 Emulator for Windows, Ber...