(42S) Eigenvalues & Eigenvectors
|
04-10-2022, 08:39 PM
(This post was last modified: 05-11-2022 07:21 PM by Michael de Estrada.)
Post: #1
|
|||
|
|||
(42S) Eigenvalues & Eigenvectors
I wrote these programs originally for the SwissMicros DM42, but they should work fine on the HP 42S, since I'm using only native HP 42s commands for a 4-level stack.
The general eigenvalue problem that is solved here is the solution to the equation: A Φ = λ I Β Φ Where, A and B are real square matrices, I is the identity matrix, Φ is the eigenvector (modeshape) and λ is an eigenvalue scalar that satisfies the relationship: | A - λ I B | = 0 The basic algorithm of this program uses the Root Solver to find the values of λ that satisfy this condition. A guess value is entered in the X register and the program EGVAL is then executed: 00 { 40-Byte Prgm } 01 LBL "EgVal" 02 PGMSLV "ZEROS" 03 STO "lambda" @ Store initial guess for λ 04 SOLVE "lambda" @ Solves for λ 05 VIEW "lambda" 06 END 00 { 40-Byte Prgm } 01 LBL "ZEROS" @ Computes | λ I B - A | 02 MVAR "lambda" 03 RCL "lambda" 04 RCLx "Ident" @Multiply scalar λ by the identity matrix Ident to ensure that only the diagonal elements of B are multiplied by λ 05 RCLx "B" 06 RCL- "A" 07 DET 08 END Note that MVAR "lambda" is unnecessary if the program EGVAL is executed. It is there to permit direct solution of ZEROS using the root solver (SOLVER). If B = I (Identity matrix), then this program solves the problem A Φ = λ Φ. The following program to computes the Eigenvectors Φ for the Eigenvalues λ. The eigenvectors are arbitrarily normalized such that the last element is unity (1). The solution steps are as follows: 1) Create the matrix C = λ I B - A 2) Create reduced n-1 x n-1 matrix D by deleting the last row and column of matrix C. 3) Create reduced n-1 x 1 vector E from the first n-1 elements of the nth column of matrix C. 4) Compute the first n-1 elements of the Eigenvector Φ = E / D. 5) Expand Φ to n x 1, and store 1 as the nth element. 00 { 106-Byte Prgm } 01 LBL "EgVec" 02 RCL "lambda" 03 RCLx "Ident" @Multiply scalar λ by the identity matrix Ident to ensure that only the diagonal elements of B are multiplied by λ 04 RCLx "B" 05 RCL- "A" 06 STO "C" 07 INDEX "C" 08 DIM? 09 1 10 - 11 X<>Y 12 1 13 - 14 GETM @Create n-1 x n-1 matrix D from first n-1 rows and columns of C 15 STO "D" 16 RCL "C" 17 DIM? 18 1 19 X<>Y 20 STOIJ 21 X<>Y 22 - 23 1 24 GETM @Create n-1 x 1 vector E from the first n-1 elements of the nth column of C 25 -1 26 x 27 RCL÷ "D" 28 STO "Phi" @Compute first n-1 elements of Eigenvector Φ 29 DIM? 30 X<>Y 31 1 32 + 33 X<>Y 34 DIM "Phi" @Expand Φ to n x 1, and store 1 as the nth element. 35 INDEX "Phi" 36 STOIJ 37 1 38 STOEL 39 RCL "Phi" @Eigenvector Φ 40 END Upon completion, the program displays the n x 1 Eigenvector Φ in the X register. The following accessory program generates the identity matrix for use with the EgVal and EgVec programs. At the prompt type n R/S, and the program will generate an n x n diagonal matrix with 1 for all the diagonal elements. 00 { 79-Byte Prgm } 01 LBL "UNIT" 02 INPUT "N" 03 ENTER 04 NEWMAT 05 STO "Ident" 06 INDEX "Ident" 07 1 08 RCL "N" 09 1ᴇ3 10 ÷ 11 + 12 STO "CountI" 13 0 14 STO "I" 15 LBL 01 16 RCL "I" 17 1 18 + 19 STO "I" 20 ENTER 21 STOIJ 22 1 23 STOEL 24 ISG "CountI" 25 GTO 01 26 END |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)