1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE>EIG Eigendecomposition of a Matrix
</TITLE>
</HEAD>
<BODY>
<H2>EIG Eigendecomposition of a Matrix
</H2>
<P>
Section: <A HREF=sec_transforms.html> Transforms/Decompositions </A>
<H3>Usage</H3>
Computes the eigendecomposition of a square matrix. The <code>eig</code> function
has several forms. The first returns only the eigenvalues of the matrix:
<PRE>
s = eig(A)
</PRE>
<P>
The second form returns both the eigenvectors and eigenvalues as two
matrices (the eigenvalues are stored in a diagonal matrix):
<PRE>
[V,D] = eig(A)
</PRE>
<P>
where <code>D</code> is the diagonal matrix of eigenvalues, and <code>V</code> is the
matrix of eigenvectors.
Eigenvalues and eigenvectors for asymmetric matrices <code>A</code> normally
are computed with balancing applied. Balancing is a scaling step
that normaly improves the quality of the eigenvalues and eigenvectors.
In some instances (see the Function Internals section for more details)
it is necessary to disable balancing. For these cases, two additional
forms of <code>eig</code> are available:
<PRE>
s = eig(A,'nobalance'),
</PRE>
<P>
which computes the eigenvalues of <code>A</code> only, and does not balance
the matrix prior to computation. Similarly,
<PRE>
[V,D] = eig(A,'nobalance')
</PRE>
<P>
recovers both the eigenvectors and eigenvalues of <code>A</code> without balancing.
Note that the 'nobalance' option has no affect on symmetric matrices.
FreeMat also provides the ability to calculate generalized eigenvalues
and eigenvectors. Similarly to the regular case, there are two forms
for <code>eig</code> when computing generalized eigenvector (see the Function
Internals section for a description of what a generalized eigenvector is).
The first returns only the generalized eigenvalues of the matrix
pair <code>A,B</code>
<PRE>
s = eig(A,B)
</PRE>
<P>
The second form also computes the generalized eigenvectors, and is
accessible via
<PRE>
[V,D] = eig(A,B)
</PRE>
<P>
<H3>Function Internals</H3>
Recall that <code>v</code> is an eigenvector of <code>A</code> with associated eigenvalue
<code>d</code> if
<P>
<DIV ALIGN="CENTER">
<IMG SRC="eig_eqn1.png">
</DIV>
<P>
This decomposition can be written in matrix form as
<P>
<DIV ALIGN="CENTER">
<IMG SRC="eig_eqn2.png">
</DIV>
<P>
where
<P>
<DIV ALIGN="CENTER">
<IMG SRC="eig_eqn3.png">
</DIV>
<P>
The <code>eig</code> function uses the <code>LAPACK</code> class of functions <code>GEEVX</code>
to compute the eigenvalue decomposition for non-symmetric
(or non-Hermitian) matrices <code>A</code>. For symmetric matrices, <code>SSYEV</code>
and <code>DSYEV</code> are used for <code>float</code> and <code>double</code> matrices (respectively).
For Hermitian matrices, <code>CHEEV</code> and <code>ZHEEV</code> are used for <code>complex</code>
and <code>dcomplex</code> matrices.
For some matrices, the process of balancing (in which the rows and
columns of the matrix are pre-scaled to facilitate the search for
eigenvalues) is detrimental to the quality of the final solution.
This is particularly true if the matrix contains some elements on
the order of round off error. See the Example section for an example.
A generalized eigenvector of the matrix pair <code>A,B</code> is simply a
vector <code>v</code> with associated eigenvalue <code>d</code> such that
<P>
<DIV ALIGN="CENTER">
<IMG SRC="eig_eqn4.png">
</DIV>
<P>
where <code>B</code> is a square matrix of the same size as <code>A</code>. This
decomposition can be written in matrix form as
<P>
<DIV ALIGN="CENTER">
<IMG SRC="eig_eqn5.png">
</DIV>
<P>
where
<P>
<DIV ALIGN="CENTER">
<IMG SRC="eig_eqn6.png">
</DIV>
<P>
For general matrices <code>A</code> and <code>B</code>, the <code>GGEV</code> class of routines are
used to compute the generalized eigendecomposition. If howevever,
<code>A</code> and <code>B</code> are both symmetric (or Hermitian, as appropriate),
Then FreeMat first attempts to use <code>SSYGV</code> and <code>DSYGV</code> for <code>float</code>
and <code>double</code> arguments and <code>CHEGV</code> and <code>ZHEGV</code> for <code>complex</code>
and <code>dcomplex</code> arguments (respectively). These routines requires
that <code>B</code> also be positive definite, and if it fails to be, FreeMat
will revert to the routines used for general arguments.
<H3>Example</H3>
Some examples of eigenvalue decompositions. First, for a diagonal
matrix, the eigenvalues are the diagonal elements of the matrix.
<PRE>
--> A = diag([1.02f,3.04f,1.53f])
A =
1.0200 0 0
0 3.0400 0
0 0 1.5300
--> eig(A)
ans =
1.0200
1.5300
3.0400
</PRE>
<P>
Next, we compute the eigenvalues of an upper triangular matrix,
where the eigenvalues are again the diagonal elements.
<PRE>
--> A = [1.0f,3.0f,4.0f;0,2.0f,6.7f;0.0f,0.0f,1.0f]
A =
1.0000 3.0000 4.0000
0 2.0000 6.7000
0 0 1.0000
--> eig(A)
ans =
1
2
1
</PRE>
<P>
Next, we compute the complete eigenvalue decomposition of
a random matrix, and then demonstrate the accuracy of the solution
<PRE>
--> A = float(randn(2))
A =
0.0501 0.1608
2.1808 -2.4972
--> [V,D] = eig(A)
V =
0.7754 -0.0599
0.6314 0.9982
D =
0.1811 0
0 -2.6282
--> A*V - V*D
ans =
1.0e-07 *
1.0431 -0.2980
-1.5646 0
</PRE>
<P>
Now, we consider a matrix that requires the nobalance option
to compute the eigenvalues and eigenvectors properly. Here is
an example from MATLAB's manual.
<PRE>
--> B = [3,-2,-.9,2*eps;-2,4,1,-eps;-eps/4,eps/2,-1,0;-.5,-.5,.1,1]
B =
3.0000 -2.0000 -0.9000 0.0000
-2.0000 4.0000 1.0000 -0.0000
-0.0000 0.0000 -1.0000 0
-0.5000 -0.5000 0.1000 1.0000
--> [VB,DB] = eig(B)
VB =
0.6153 -0.4176 -0.0000 -0.1530
-0.7881 -0.3261 -0.0000 0.1346
-0.0000 -0.0000 0.0000 -0.9790
0.0189 0.8481 1.0000 -0.0097
DB =
5.5616 0 0 0
0 1.4384 0 0
0 0 1.0000 0
0 0 0 -1.0000
--> B*VB - VB*DB
ans =
0.0000 -0.0000 -0.0000 0.0000
-0.0000 -0.0000 0.0000 0.0000
-0.0000 -0.0000 -0.0000 0
-0.0000 0.0000 0 -0.1081
--> [VN,DN] = eig(B,'nobalance')
VN =
0.6153 -0.4176 0.0000 -0.1528
-0.7881 -0.3261 0.0000 0.1345
-0.0000 -0.0000 -0.0000 -0.9781
0.0189 0.8481 -1.0000 0.0443
DN =
5.5616 0 0 0
0 1.4384 0 0
0 0 1.0000 0
0 0 0 -1.0000
--> B*VN - VN*DN
ans =
1.0e-16 *
8.8818 -1.1102 -1.6722 -1.1102
-8.8818 2.7756 0.1811 0.8327
0.1718 0.0154 0.0663 0
-0.6939 0 0 0.8327
</PRE>
<P>
</BODY>
</HTML>
|