TUmatrixEig TCL UTILITIES USER MANUAL TUmatrixEig
SYNOPSIS
Find eigenvectors and eigenvalues of a symmetric matrix
PACKAGE
TCLUTILS
NAME
TUmatrixEig
USAGE
set rV  [TUmatrixEig  M N Val Vec]
INPUT DEFINITIONS
M - Input matrix. This must be a symmetric matrix, that is, M must equal its transpose.
N - Dimension of matrix being inverted
Val - The eigenvalues.
Vec - The eigenvectors returned as a matrix or order N. Each eigenvecotor is a column in the matrix.
RETURN DEFINITION
Number of Jacobi rotations needed to reach solution
DESCRIPTION
TUmatrixEig uses a Jacobi transformation to solve for the eigenvalues and eigenvectors of a summetric matrix. The input matrix is not preserved in the solution. The eigenvectors are returned in a matrix of the same order as the input matrix along the martix columns. The matrix is returned row by row so that for and order N matrix the first eigenvector is made of the elements: Vec(0), Vec(N), Vec(2N), Vec(3N) ... Vec(N2.
ERRORS
None Generated
C BACKING
No
EXAMPLE(S)
# SOLVE for the eigenvector and eigenvalues of a matrix

# BUILD a 4x4 symmetric matrix V and a copy of it Vc

set V(0)    1.0 ; set V(1)  -2.0 ; set V(2)   7.0 ; set V(3)    4.0
set V(4)   -2.0 ; set V(5)   6.0 ; set V(6)  -3.0 ; set V(7)   -8.0
set V(8)    7.0 ; set V(9)  -3.0 ; set V(10)  5.0 ; set V(11)   9.0
set V(12)   4.0 ; set V(13) -8.0 ; set V(14)  9.0 ; set V(15) -10.0

for { set I 0 } { $I < 16 } { incr I } { set Vc($I) $V($I) }

# SOLVE of the eigenvector and eigenvalues

set nR [TUmatrixEig V 4 VaL VeC]  

# PRINT RESULTS

puts stderr "EigenValues:" 
for { set I 0 } { $I < 4 } { incr I } { 
    puts stderr "  $I : [format "%7.3f" $VaL($I)]" 
}

puts stderr "\nEigenVectors:" 
set K 0
for { set I 0 } { $I < 4 } { incr I } { 
   set OutPut "  $I : "
   for { set J 0 } { $J < 4 } { incr J ; incr K } { 
       append OutPut [format "%9.3f" $VeC($K)] 
   }
   puts stderr $OutPut
}

# CHECK of Eigenvector 0

set eV(0) $VeC(0)  ; set ChK(0) [expr $eV(0) * $VaL(0)]
set eV(1) $VeC(4)  ; set ChK(1) [expr $eV(1) * $VaL(0)]
set eV(2) $VeC(8)  ; set ChK(2) [expr $eV(2) * $VaL(0)]
set eV(3) $VeC(12) ; set ChK(3) [expr $eV(3) * $VaL(0)]

TUmatrixMath Vc * eV ReS 4 4 4 1

puts stderr "\nCheck EigenVector 0:" 
for { set I 0 } { $I < 4 } { incr I } { 
   puts stderr "  CHECK $I [format "%7.3f %9.3f" $ReS($I) $ChK($I)]" 
}

>EigenValues:
>  0 :  -4.008
>  1 :   4.115
>  2 :  17.876
>  3 : -15.983
>
>EigenVectors:
>  0 :     0.823    0.381    0.419   -0.042
>  1 :    -0.103    0.810   -0.506    0.278
>  2 :    -0.544    0.441    0.632   -0.332
>  3 :    -0.130   -0.070    0.410    0.900
>
>Check EigenVector 0:
>  CHECK 0  -3.298    -3.298
>  CHECK 1   0.411     0.411
>  CHECK 2   2.178     2.178
>  CHECK 3   0.522     0.522

      
July 25, 2003