[comp.sys.handhelds] Eigenvalues

wscott@EN.ECN.PURDUE.EDU (Wayne H Scott) (02/26/90)

I have always used the symbolic matrix programs to compute Eigenvalues until
today when I discovered a fast and simple way to do it using the hp28
solver.

The solver can the zero of a function or even a program if it does not take a
number off the stack and returns one number to the stack.  

Enter the following program into your HP.

<< A DUP IDN X * - DET >>

Now press STEQ and enter the solver.

A and X appear on the menus.  Enter the matrix you want to have the Eigenvalues
of and press A.  Now enter you first guess for X and press X.  Press shift X
and the solver will come up with a value.

I don't know about you people but I was very exicited when I discovered how
easily the system that already exists allows you to solver this problem.

Note: Inital test show that this is much faster than using other Eigenvalue
      programs.

_______________________________________________________________________________
Wayne Scott             |  INTERNET:   wscott@en.ecn.purdue.edu
Electrical Engineering  |  BITNET:     wscott%ea.ecn.purdue.edu@purccvm
Purdue University       |  UUCP:      {purdue, pur-ee}!en.ecn.purdue.edu!wscott

akcs.jwendel@hpcvbbs.UUCP (James G. Wendel) (12/20/90)

Someone posted a message containing the program
\<<A I L * - DET \>> (where I = Identity matrix)
for finding the characteristic polynomial of a matrrix A.
I can't make it work because the 48 doesn't seem to permit
symbolic entries in arrayse, as was also the case with the 28s
Can someone give me the reference to this message?
Thanks...jim_wendel@ub.cc.umich.edu or jwendel@isdmnl.wr.usgs.gov
 

john%solvint@orstcs.UUCP (12/21/90)

> Someone posted a message containing the program
> \<<A I L * - DET \>> (where I = Identity matrix)
> for finding the characteristic polynomial of a matrrix A.
> I can't make it work because the 48 doesn't seem to permit
> symbolic entries in arrayse, as was also the case with the 28s
> Can someone give me the reference to this message?
> Thanks...jim_wendel@ub.cc.umich.edu or jwendel@isdmnl.wr.usgs.gov
> 
> 

Symbollic entries in arrays is not the point.

One uses this program by making it the current SOLVER equation, putting a square
array in 'A', the square identity in 'I' and solving for 'L', the eigenvalue.
This program looks like it was taken from the "Easy Course in Using the HP-28S"
where it was used to solve for the eigenvalues of matrix 'A', but since the 28
doesn't have the lambda character, L was used instead.

To use it to find the characteristic polynomial of [[ 1 2 ][ 3 2 ]], do the
following:

\<< A I * - DET \>> [lshift] [SOLVE] [STEQ] [SOLVR] 
[[ 1 2 ][ 3 2 ]] [A]
[[ 1 0 ][ 0 1 ]] [I]
-100 [L]                @ as a guess
[lshift] [L] ==> L: -1
100 [L]                 @ as a guess
[lshift] [L] ==> L: 4

To create the polynomial from these, subtract each from T and multiply:

'T' SWAP - SWAP 'T' SWAP - *

This gives '(T+1)*(T-4).  Expanding:

EXPAN EXPAN COLCT

gives '-4+T^2-3*T'

--
John W. Loux                    | Solve and Integrate Corp
solvint!john@orstcs.cs.orst.edu | PO Box 1928
john@solvint.uucp               | Corvallis, OR 97339-1928
                                | (503) 754-1207

jacobsd@usenet@scion.CS.ORST.EDU (Dana Jacobsen) (12/22/90)

In <9012201714.AA26392@CS.ORST.EDU> john%solvint@orstcs.UUCP writes:

>> Someone posted a message containing the program
>> \<<A I L * - DET \>> (where I = Identity matrix)
>> for finding the characteristic polynomial of a matrrix A.
>> I can't make it work because the 48 doesn't seem to permit
>> symbolic entries in arrayse, as was also the case with the 28s
>> Can someone give me the reference to this message?
>> Thanks...jim_wendel@ub.cc.umich.edu or jwendel@isdmnl.wr.usgs.gov
>> 
>> 

>Symbollic entries in arrays is not the point.

>One uses this program by making it the current SOLVER equation, putting a square
>array in 'A', the square identity in 'I' and solving for 'L', the eigenvalue.
>This program looks like it was taken from the "Easy Course in Using the HP-28S"
>where it was used to solve for the eigenvalues of matrix 'A', but since the 28
>doesn't have the lambda character, L was used instead.

  The HP-28 solution book "Matrices & Vectors" has a more elegant solution that
is probably faster and works better in that you don't have to call the solver.
I wrote a plug-and-chug program around this.  Enter the matrix, press the key,
and you get back the eigenvalues.
  It works by finding the characteristic polynomial, then solving for that.
I posted this a while ago, but some peopl seem to have missed it, and I also 
left out the root-finding programs.  This program needs some way of solving an
arbitrary degree polynomial.  The program "BAIRS" which came by the net a
while back seems to do the job well.  I don't remember who wrote this though
(Wayne Scott?).   
  All the programs are available via anonymous FTP from scion.cs.orst.edu
(128.193.32.25):~ftp/pub/jacobsd/{hp.eig,hp.proot}.

%%HP: T(3)A(R)F(.);
      EIGVAL
        \<< DUP DUP
SIZE 1 GET \-> t g n
          \<< { } 1 n
            START 0
1 n
              FOR i
t i DUP 2 \->LIST GET
+
              NEXT
1 \->LIST + 't' g
STO*
            NEXT \->
b
            \<< { 1 }
1 n
              FOR i
\-> s
\<< 0 1 i
  FOR j b j GET s i
j - 1 + GET * -
  NEXT i / 1 \->LIST
s SWAP +
\>>
              NEXT
            \>>
          \>> PROOT
        \>>

  This is my eigenvalue program.  PROOT is a program that will solve f(x)=0
for a polynomial.  It takes a list of numbers which are coefficients for the
polynomial (i.e. "4 * x^2 + 3 * x - 3" would be { 4 3 -2 } ).  Programs for
this are available on the net, or I could send mine to you.  (Or you can
anonymous ftp it from scion.cs.orst.edu:pub/jacobsd/proot & math)  The 
files aren't in great shape (^M's at the end of each line) but it's there.

    Start:     An n x n matrix in level 1
    Stop:      n real or complex values on the stack.  These are the 
	       eigenvalues.

%%HP: T(3)A(R)F(.);
PROOT
\<< DUP SIZE \-> n
  \<<
    IF n 3 >
    THEN DUP { HOME
MATH POLY BAIRS }
RCL EVAL SWAP OVER
{ HOME MATH POLY
PDIV } RCL EVAL
DROP2 \-> a b
      \<< a PROOT b
PROOT
      \>>
    ELSE
      IF n 2 >
      THEN { HOME
MATH POLY QUD } RCL
EVAL
      ELSE LIST\->
DROP NEG SWAP /
      END
    END
  \>>
\>>

BAIRS
\<< LIST\-> 1 1
\-> n R S
  \<<
    DO 0 n
1 + PICK 0 0 0 4
PICK 5 n + 7
    FOR J
J PICK R 7 PICK * +
S 8 PICK * + 7 ROLL
DROP DUP 6 ROLLD R
3 PICK * + S 4 PICK
* + 5 ROLL DROP -1
    STEP
3 PICK SQ 3 PICK 6
PICK * -
      IF
DUP 0 ==
      THEN
DROP 1 1
      ELSE
6 PICK 6 PICK * 5
PICK 9 PICK * -
OVER / 4 PICK 9
PICK * 8 PICK 7
PICK * - ROT /
      END
DUP 'S' STO+ SWAP
DUP 'R' STO+
    UNTIL
R\->C ABS .000000001
< 7 ROLLD 6 DROPN
    END n
DROPN 1 R NEG S NEG
3 \->LIST
  \>>
\>>

QUD
\<< LIST\->
\->ARRY DUP 1 GET /
ARRY\-> DROP ROT DROP
SWAP 2 / NEG DUP SQ
ROT - \v/ DUP2 + 3
ROLLD -
\>>


  That's it.  Hope everything works fine -- I don't have a cable to transfer
the stuff, so got a friend to do the transfer..
--
Dana Jacobsen                       Oregon State University
jacobsd@cs.orst.edu                   Computer Science
..!hplabs!hp-pcd!orstcs!jacobsd
Dana_Jacobsen@RPITSMTS.BITNET            `Once a daemon, always a daemon'