' ******************************************************************
' Eigenvalues of a general square matrix
' ******************************************************************

' ------------------------------------------------------------------
' Type definition
' ------------------------------------------------------------------

TYPE Complex
  X AS DOUBLE
  Y AS DOUBLE
END TYPE

' ------------------------------------------------------------------
' External functions
' ------------------------------------------------------------------

DECLARE SUB Balance(      A()     AS DOUBLE,  _ 
                    BYREF Lo      AS INTEGER, _ 
                    BYREF Hi      AS INTEGER, _ 
                          Scale() AS DOUBLE)
' Balances a matrix and tries to isolate eigenvalues

DECLARE SUB ElmHes(A()     AS DOUBLE,  _ 
                   Lo      AS INTEGER, _ 
                   Hi      AS INTEGER, _ 
                   Inter() AS INTEGER)
' Reduction of a square matrix to upper Hessenberg form
                    
DECLARE SUB Hqr(H()      AS DOUBLE,  _ 
                Lo       AS INTEGER, _ 
                Hi       AS INTEGER, _ 
                Lambda() AS Complex) 
' Eigenvalues of a real upper Hessenberg matrix by QR method

' ******************************************************************

SUB EigenVals(A() AS DOUBLE, Lambda() AS Complex)

  DIM AS INTEGER Lb, Ub, Lo, Hi
  
  Lb = LBOUND(A, 1)
  Ub = UBOUND(A, 1)

  DIM AS DOUBLE  Scale(Lb TO Ub) 
  DIM AS INTEGER Inter(Lb TO Ub)

  Balance A(), Lo, Hi, Scale()
  ElmHes A(), Lo, Hi, Inter()
  Hqr A(), Lo, Hi, Lambda()
END SUB
