Showing posts with label algorithm. Show all posts
Showing posts with label algorithm. Show all posts

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.

Saturday, April 12, 2025

RPN with HP 15C & DM32: Stack Register Arithmetic

RPN with HP 15C & DM32: Stack Register Arithmetic


Got a treat for today folks. First...


14 YEARS!!


On the 16th, it will be 14 years since my blog started!!!! Thank you so much for your support – the blog is one of my joys of life.


Today is another installment of RPN with HP 15C & DM32, I hope you are enjoying this new monthly series, currently every second Saturday of the month.



Stack Register Arithmetic


As we know, nearly all Hewlett Packard (HP) and I think all Swiss Micros (SM) calculators that operate on Reverse Polish Notation (RPN) or Reverse Polish Lisp (RPL, think HP 48 and 50g), a feature that we can calculate an arithmetic operation (+, -, ÷, ×) directly on any number stored in any memory register. It’s a very handy feature indeed.


On the HP 41C, DM41, HP 42S, and DM42 series of calculators, that ability extend to the stack registers themselves (X, Y, Z, T, L (LastX)). To do this, press [ STO ], the required arithmetic operation, the decimal point [ . ], and the appropriate key.


Example:


The current stack is set as:


T: 11

Z: 16

Y: 10

X: 5


Note the 5 in the X stack. We can use the contents of the X stack to do operations on the other levels without “disturbing” the other levels.


Add 5 to stack Z without having to disturb the stack. ST+ Z (41), STO+ ST Z (42) returns:


T: 11

Z: 21

Y: 10

X: 5


Note that the entire stack except Z remains the same.


Multiply stack T by 5. 5 is in the X stack already. ST* T (41), STO× ST T (42) returns:


T: 55

Z: 21

Y: 10

X: 5


Pretty neat, right?


In summary:


STO+ SL: new SLV= old SLV + X

STO- SL: new SLV = old SLV – X

STO× SL: new SLV = old SLV × X

STO÷ SL: new SLV = old SLV ÷ X


where:

X = value in stack level X (display on one-line calculators)

SLV = stack value level (X, Y, Z, T, L)


The 15C and 32S series do not have a native way to do this, but today I will present a way to mimic these powerful stack storage arithmetic on levels X, Y, Z, and T. Most of them will not require the use of an outside memory register (i.e. R0 or R1 for the 15C series, or A or Z for the 32S series).


These techniques were tested on a Hewlett Packard HP 15C and Swiss Micros DM32. They probably would work on the HP 12C (or equivalent) as well, just substitute the roll up (R↑) with three roll down (R↓ R↓ R↓) commands when encountered.


FYI, the 42 series also has recall arithmetic on stack levels, which returns on stack X.



The Algorithms


For the following algorithms, let {OP} stand for the arithmetic operation (+, -, ×, ÷). Let the hash symbol, {#}, stack for a register of your choice (i.e. R0 for 15 or A for 32).


Storage Arithmetic on Stack X


R↑

STO {#}

R↓

ENTER

{OP}

RCL {#}

R↓




Stack Illustration with STO+ X (it will be similar with the rest of the arithmetic operations)


t

z

z

t

z

z

z

t

z

y

y

z

y

z

y

z

y

x

x

y

x

y

x + x

y

x

t

t

x

x

x + x

t

x + x

START

R↑

STO {#}

R↓

ENTER

+

RCL {#}

R↓


Shortcuts:

STO- X: Clx

STO× X: x^2 (specifically, the square function)


The next set will not require a separate memory register.


Example:


40

30

30

40

30

30

30

40

30

20

20

30

20

30

20

30

20

10

10

20

10

20

20

20

10

40

40

10

10

10 + 10 = 20

40

20

START

R↑

STO {#}

R↓

ENTER

+

RCL {#}

R↓





Storage Arithmetic on Stack Y


This is by far the easiest.


{OP}

LAST X


Stack Illustration with STO+ Y (it will be similar with the rest of the arithmetic operations)


t

t

t

z

t

z

y

z

y + x

x

y + x

x

START

+

LAST X



Example:


40

40

40

30

40

30

20

30

30

10

20 + 10 = 30

10

START

+

LAST X




Storage Arithmetic on Stack Z


x<>y

R↓

{OP}

LAST X

R↑

x<>y


Stack Illustration with STO+ Z (it will be similar with the rest of the arithmetic operations)


t

t

y

y

y

t

t

z

z

t

y

t

z +x

z + x

y

x

z

t

z + x

x

y

x

y

x

z + x

x

y

x

START

x<>y

R↓

+

LAST X

R↑

x<>y



Example:


40

40

20

20

20

40

40

30

30

40

20

40

40

40

20

10

30

40

40

10

20

10

20

10

30 + 10 = 40

10

20

10

START

x<>y

R↓

+

LAST X

R↑

x<>y




Storage Arithmetic on Stack T


R↑

x<>y

{OP}

LAST X

x<>y

R↓



Stack Illustration with STO+ T (it will be similar with the rest of the arithmetic operations)


t

z

z

z

z

z

t + x

z

y

y

z

y

y

z

y

x

t

y

t + x

x

y

x

t

x

t + x

x

t + x

x

START

R↑

x<>y

+

LAST X

x<>y

R↓


Example:


40

30

30

30

30

30

50

30

20

20

30

20

20

30

20

10

40

20

50

10

20

10

40

10

40 + 10 = 50

10

50

10

START

R↑

x<>y

+

LAST X

x<>y

R↓



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.


RPN: DM32 and DM42: Stopping Sight Distance (Metric)

RPN: DM32 and DM42: Stopping Sight Distance (Metric) The Stopping Sight Distance Formula – Derivation The stopping sight di...