Re: Compute some Eigenvalues first thing in the morning, and nothing worse will happen to you all day. Message #6 Posted by Valentin Albillo on 14 July 2006, 8:29 a.m., in response to message #1 by Eric Smith
Hi, Eric:
Eric posted:
"Actually it is fun, though a bit tedious."
Yes, I concur, I do it every morning as well and sometimes also before going to sleep. This is how I do it, extracted from my Datafile article "HP71B  Math ROM Baker's Dozen  Vol 2", freely downloadable from here:
"The general case of finding all eigenvalues of any square matrix
is hardly any more difficult, as demonstrated by this 5liner
that will accept any square matrix and will promptly compute
both the coefficients of its Characteristic Polynomial and all
its eigenvalues, real and/or complex:
1 DESTROY ALL
@ OPTION BASE 0
@ FIX 5
@ INPUT "N=";N
@ M=N1
2 DIM A(M,M),U(M,M),C(N),D(N,N)
@ COMPLEX E(N)
@ MAT INPUT A
3 MAT D=CON
@ MAT U=IDN
@ FOR I=0 TO N
@ IF I THEN MAT A=AU
4 C(I)=DET(A)
@ FOR J=1 TO N
@ D(I,NJ)=I^J
@ NEXT J
@ NEXT I
5 MAT C=SYS(D,C)
@ MAT DISP C
@ MAT E=PROOT(C)
@ MAT DISP E
Once the matrix has been entered, all it does is use DET (Determinant)
to find N+1 values of the Characteristic Polynomial, then
MAT ... SYS is used to explicitly find (and display) the
coefficients of this polynomial [...] then all its roots
(the eigenvalues) real and/or complex are computed at once
by PROOT and displayed as well.
Let’s test it with the same 5x5 matrix as before:
>RUN [ENTER]
N=5 [ENTER]
A(0,0)? 5,1,2,0,4,1,4,2,1,3,2,2,5,4,0,0,1,4,1,3,4,3,0,3,4 [ENTER]
1.00000 19.00000 79.00000 146.00000 1153.0000 1222.00000
(1.49766, 0.00000)
(3.36188, 0.00000)
(3.55784,0.00000)
(5.67255,0.00000)
(12.02575,0.00000)
so the Characteristic Polynomial is :
P(x)= x^{5} + 19 x^{4}  79 x^{3}  146 x^{2} + 1153 x  1222
and, as expected in this case, as this is a symmetric matrix,
all five eigenvalues are real (imaginary parts = 0):
x_{1} = 1.49766
x_{2} = 3.36188
x_{3} = 3.55784
x_{4} = 5.67255
x_{5} = 12.02575
You can verify them by checking that their product equals the
matrix determinant (DET(A) = 1222). To verify the Characteristic
Polynomial, you can apply it to the matrix itself: the resulting
value should be a zero matrix, i.e.: P(A) = ZER"
Best regards from V.
