Post Reply 
HP35S - Eigenvalues & eigenvectors of a 3x3 matrix (but also determinant, inv., etc.)
04-21-2024, 05:45 AM (This post was last modified: 04-21-2024 05:47 AM by Roberto Volpi.)
Post: #1
HP35S - Eigenvalues & eigenvectors of a 3x3 matrix (but also determinant, inv., etc.)
Hi all,

this an update of an already submitted program:

https://www.hpmuseum.org/forum/thread-20563.html

to include new features.

The program, instructions and reference info are all in the attached Excel file

This program will evaluate in a 3x3 matrix with ℝ entries:

• Determinant
• Inverse matrix
• Cross product and angle formed by two 3D vectors.
• Multiplication between two 3x3 matrices
• Gram matrix (A-Transposed by A)
• Eigenvalues
• Eigenvectors
• Verify if an eigenvector is correct
• LU decomposition Crout method
• LU decomposition Cholesky’s method

As it is organised in a modular way, it is possible to add more functions later.

It uses as subroutine 2 programs: one in LBL C to find roots in cubic and quadratic polynomial, which is an updated version of:

https://www.hpmuseum.org/forum/thread-19783.html

essentially by introducing some change in registers’ usage in order not to interfere with matrix registers, and, in LBL X, other short subroutines to expand a vector on the stacks, to extract real or imaginary part from a given number, etc.

AN EASY EXAMPLE:

Matrix entries are input on stacks row by row. Let’s try with the following matrix:

[1 2 3]
[4 5 6]
[7 8 -9]

Input this matrix as follows by pressing:

1 ENTER 2 ENTER 3 XEQ M ENTER
4 ENTER 5 ENTER 6 R/S
8 ENTER 8 ENTER -9 R/S

Our HP35S will display its determinant as:

>D= 54

Press again R/S to obtain the inverse of our matrix:

> stack t: 54
> stack z: [-1.722..., 0.77..., -0,055...]
> stack y: [1.44..., 0.55..., 0.11...]
> stack x: [-0.055..., -0,211..., -0.055...]

Stack t will display the determinant, and the others the inverse of A in vector form: 1st row on stack z, 2nd row on stack y and 3rd row on stack x. Those row vector are automatically stored in STO K, STO L, STO M respectively.

This matrix will remain stored for later use, row by row, in STO S, STO Q and STO R, so it is possible to perform other operations with that same matrix.

In the excel file, beside the programs, detailed usage instructions and a registers usage guide have been included.

ABOUT EIGENVALUES

As eigenvalues are found by solving the related cubic characteristic polynomial, we could obtain both real and complex solutions. This program can use real solutions to find its related eigenvectors, but not complex solutions, since our HP35S may not accept complex numbers as vector entries.

Furthermore, in case of all 3 real solutions, 2nd and 3rd eigenvector appear always in complex format (ex. 16i0 instead of just 16) and that i0 imaginary part must be removed. In case the solution is a long decimal number, just XEQ X037 and we shall remain with just the real part.

ABOUT EIGENVECTORS

Here comes the tricky part.

As a result, our HP35S will give 3 eigenvectors which are not necessarily bases, but more often their linear combinations, so finding those bases could require some ingenuity.

Furthermore, in case geometrical multiplicity coming from degenerate eigenvalues, we shall face a breakdown case, but let’s illustrate that with an example, taken from “Advanced Engineering Mathematics” by Erwin Kreyszig, 7th edition 1993:

Exercise #19 from problem set 7.10, pag. 391

Find the eigenvalues and the eigenvectors of:

[8 0 3]
[2 2 1]
[2 0 3]

Input the matrix as explained, and we shall obtain at once 36 as determinant:

Press XEQ M107

>stack y: 0.00000001
>stack x: 9

So 1st eigenvalue is 9, and 0.00000001 is the accuracy range (well, we already know it is exact indeed)

Press R/S

>stack y: 2i0
>stack x: 2i0

2nd and 3rd eigenvalues are 2

Now let’s find the related eigenvectors.

For eigenvector related to ?=9 press:

9 XEQ M184

And we shall obtain:

> stack t: 9
> stack z: [42, 14, 14]
> stack y: [0, 0, 0]
> stack x: [21, 7, 7]

Stack t shows the related eigenvalues, [0, 0, 0] is clearly not an acceptable solution, and in this case it is easy to see that the best solution for ?=9 is [3, 1, 1].
Now let’s see what happens if we input a degenerate eigenvalue.

For eigenvector related to ?=2 press:

2 XEQ M184

And we shall obtain:

> stack t: 2
> stack z: [0, 0, 0]
> stack y: [0, 0, 0]
> stack x: [0, 0, 0]

That means geometric and not just algebraic multiplicity for ?=2

To solve that, input the “other” value for eigenvalue and press R/S

9 R/S

And we shall obtain

> stack t: 9
> stack z: [-1, 2, 2]
> stack y: [0, -7, 0]
> stack x: [3, 1, -6]

From stack y we easily find [0, 1, 0]. Subtract this from vector on stack x [3, 1, -6] and we shall have [3, 0, -6], which shall lead us to [1, 0, -2].

Check the eigenvectors by inputing related eigenvalue, so pressing 2 and x< >y, so to have ?=2 on the stack y and the vector to verify on the stack x, press R/S, and if we obtain as a result 2 equal vectors on both stacks (correspondent to Ax= ? of course), we are right.

Please note that, to check a vector, we press R/S only if we are after a breakdown case, otherwise we must press XEQ M194.

But what happens in case of an eigenvalue repeated 3 times?

Let’s solve an exercise taken from “Mathematical Methods for Physics and Engineering” by Riley, Hobson and Bence, 3rd edition 2018.

Exercise 8.20 page 311.

Demostrate that the matrix

[ 2 0 0]
[-6 4 0]
[ 3 -1 0]

Is defective, i.e. does not have 3 linearly independent solutions, and that its eigenvalues are degenerate and all equal.

Input matrix as usual and obtain at once 8 as determinant.

To find the eigenvalues, press XEQ M107

>stack y: 0.00000001
>stack x: 2

Press R/S

>stack y: 2i0
>stack x: 2i0

We see the eigenvalue ?=2 is repeated three times.

Try to find the eigenvectors, by pressing 2 XEQ M184 and we shall obtain:

> stack t: 2
> stack z: [0, 0, 0]
> stack y: [0, 0, 0]
> stack x: [0, 0, 0]

which is the breakdown case, but as we don’t have a separate eigenvalue to input, we have to use again ?=2, so press 2 and R/S, and we shall obtain:

> stack t: 2
> stack z: [0, -6, 3]
> stack y: [0, 2, -1]
> stack x: [0, 4, -2]

[0, 2, -1] is then the “best” solution and no other linearly independent eigenvectors are found.



I hope no typo has been made.

Enjoy


Attached File(s)
.xlsx  MY MATRIX.xlsx (Size: 31.79 KB / Downloads: 8)



Put a calculator into your life!
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)