Showing posts with label algorithm. Show all posts
Showing posts with label algorithm. 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, January 31, 2026

RPN: HP 11C: Transferring Between Bases (Common/Natural)

RPN: HP 11C: Transferring Between Bases (Common/Natural)



All algorithms were tested with the HP 11C.



Between the Exponential Function and Common-Antilog


e^α = 10^ß


Given α, what is ß?


ß = log(e^α)


RPN:

<input α>

e^x

LOG


Examples (Fix 6):

e^1.05 = 10^ß

ß ≈ 0.456009


e^(-2.2) = 10^ß

ß ≈ -0.955448


Given ß, what is α?


α = ln(10^ß)


RPN:

<input ß>

10^x

LN


Examples (Fix 6):

e^α = 10^5.4

α ≈ 12.433960


e^α = 10^0.366

α ≈ 0.842746


Between the Natural Logarithm and Common Logarithm


log α = ln ß


Given α, what is ß?

ẞ = exp(log α)


RPN:

<input α>

LOG

e^x


Examples (Fix 6):

log 17 = ln ß

ß ≈ 3.422766


log 317 = ln ß

ß ≈ 12.195405



Given ß, what is α?

α = 10^(ln ß)



RPN:

<input ß>

LN

10^x



Examples (Fix 6):

log α = ln 425

α ≈ 1,127,428.915



log α = ln 9.81

α ≈ 192.044677




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, June 28, 2025

fx-991 CW: Finding the Eigenvalues of a 2 x 2 Matrix

fx-991 CW: Finding the Eigenvalues of a 2 x 2 Matrix



Finding the Eigenvalues of a 2 x 2 Matrix


To find the eigenvalues of a matrix M, the characteristic polynomial must be solved in terms of λ:


det( M – λ * I) = 0


where:

M = a square matrix of dimension n x n

I = an identity matrix of size n x n.


The identity matrix is a square matrix in which all elements have a value 0 except the diagonal elements, which have the value 1.


A 2 x 2 identity matrix: [ [ 1, 0 ] [ 0, 1 ] ]

A 3 x 3 identity matrix: [ [ 1, 0, 0 ] [ 0, 1, 0 ] [ 0, 0, 1 ] ]


For a 2 x 2 matrix:


M = [ [ a, b ] [ c , d ] ]


The characteristic polynomial used to find the eigenvalues are:


det( M – λ * I) = 0

det( [ [ a, b ] [ c , d ] ] - λ * [ [ 1, 0 ] [ 0, 1 ] ] ) = 0

det( [ [ a, b ] [ c , d ] ] - [ [ λ, 0 ] [ 0, λ ] ] ) = 0

det( [ [ a - λ, b ] [ c , d - λ ] ] ) = 0

(a – λ) * (d – λ) – b * c = 0

λ^2 – (a + d) * λ + (a * d – b * c) = 0


Note:

trace(M) = a + d

det(M) = a * d – b * c


The characteristic equation to be solved is:


λ^2 – (a + d) * λ + (a * d – b * c) = 0

λ^2 – trace(M) * λ + det(M) = 0



Casio fx-991CW Algorithm


The algorithm will involve two apps: Matrix and Equation. Here is a way of finding the eigenvalues of a 2 x 2 matrices using only the fx-991 CW calculator without the need for writing anything down.


Note: The variables I use in the procedure is just for illustrative purposes. You can use any variables you want to designate the corner elements, the trace, and the determinant. The point is to be organized.


Variables used in this procedure:

A = upper-left element

B = lower-right element

C = trace = A + B

D = determinant


Settings: It is assumed that the MathI/MathO Input/Output mode and a+bi is selected for Complex result.


The screen shots are generated using the ClassPad Math (classpad.net) emulator for the fx-991CW and illustrates finding the eigenvalues of the matrix:


MatA = [ [ 4, 2 ] [ 5, 4 ] ]


Matrix App


Step 1: Press the [ HOME ] key, select the Matrix app.


Step 2: Use the TOOLS key to define a Matrix of dimension 2 x 2.


Step 3: Enter the matrix’s elements. Register each element is registered by using [ OK ] or [ EXE ]. Be careful not to press [ EXE ] or [ OK ] without entering a value first, as we need to keep the matrix editing screen up.


Step 4: Go to element (1,1) (upper-left hand corner), press the [ VARIABLE] key, go to variable A, press [ OK ], and select Store. Then go to element (2,2) (lower-right hand corner), press the [ VARIABLE] key, go to variable B, press [ OK ], and select Store.**


Step 5: Without entering or editing an element, press either [ EXE ] or [ OK ] to leave the matrix editor. When the message “Press [TOOLS] to define Matrix.” appears, we are in the calculation mode of the Matrix app.


Note: If you leave the matrix edit mode before storing the corner elements, you can go back into matrix edit mode by pressing [ TOOLS ], selecting your matrix, and then selecting Edit. You can check to see if corner values are stored by pressing [ VARIABLE ].





Step 6: Press [ SHIFT ] [ 4 ] (A) + [ SHIFT ] [ 7 ] ( B ) [ EXE ]. This calculates the matrix’s trace. Then press [ VARIABLE ], choose C, press [ OK ], choose Store.


Step 7: Press [ CATALOG ], select the Matrix sub-menu, then the Matrix Calc sub-menu, and select Determinant. Then use the catalog to grab the matrix and press [ EXE ] to calculate the matrix. Use the variable list to store the value in D (similar procedure in Step 6).





When transferring between apps, the values stored in the memory registers A-F, x, y, and z are retained, even when the fx-991CW is turned off.


Equations App


Step 8: Press [ HOME ] and select the Equation app and press [ OK ]. Select Polynomial, ax²+bx+c (2nd order polynomial, quadratic equation).


Step 9: Enter the following coefficients: 1 x² – C x + D (note the minus sign on C).


Step 10: Press [ OK ]. The first eigenvalue is displayed. Press the down arrow ([↓]) to get the other eigenvalue. 

 An optional step is to use the [ VARIABLE ] key to store the results (like in E or F, for example). 

 Another optional step is to press [ FORMAT ], select Decimal to see the decimal approximation.





The results are:


C = trace = 8

D = determinant = 6

Eigenvalues:

λ1 = 4 + √10

λ2 = 4 - √10



Other Examples



Find the eigenvalues of Mat B = [ [ -8, 1 ] [ 16, 7 ] ]


Results:

C = trace = -1

D = determinant = -72

Eigenvalues:

λ1 = 8

λ2 = -9





Find the eigenvalues of Mat C = [ [ -5, -7 ] [ 3, - 2] ]


Results:

C = trace = -7

D = determinant = 31

Eigenvalues:

λ1 = (-7 + 5 * √3 * i) / 2

λ2 = (-7 - 5 * √3 * i) / 2




I hope you find this useful and beneficial. 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.

Numworks: Text Demos with a Poem and Rolling Screen Credits

Numworks: Text Demos with a Poem and Rolling Screen Credits  The two scripts, which developed in Numworks: nwtext1.py: Displayin...