File: transforms_eig.html

package info (click to toggle)
freemat 4.2%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 141,800 kB
  • ctags: 14,082
  • sloc: ansic: 126,788; cpp: 62,046; python: 2,080; perl: 1,255; sh: 1,146; yacc: 1,019; lex: 239; makefile: 100
file content (222 lines) | stat: -rw-r--r-- 10,189 bytes parent folder | download | duplicates (2)
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>FreeMat: EIG Eigendecomposition of a Matrix</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">FreeMat
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.1.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="pages.html"><span>Related&#160;Pages</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('transforms_eig.html','');});
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">EIG Eigendecomposition of a Matrix </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>Section: <a class="el" href="sec_transforms.html">Transforms/Decompositions</a> </p>
<h1><a class="anchor" id="Usage"></a>
Usage</h1>
<p>Computes the eigendecomposition of a square matrix. The <code>eig</code> function has several forms. The first returns only the eigenvalues of the matrix: </p>
<pre class="fragment">  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): </p>
<pre class="fragment">  [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.</p>
<p>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: </p>
<pre class="fragment">  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, </p>
<pre class="fragment">  [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.</p>
<p>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> </p>
<pre class="fragment">  s = eig(A,B)
</pre><p> The second form also computes the generalized eigenvectors, and is accessible via </p>
<pre class="fragment">  [V,D] = eig(A,B)
</pre> <h1><a class="anchor" id="Function"></a>
Internals</h1>
<p>Recall that <code>v</code> is an eigenvector of <code>A</code> with associated eigenvalue <code>d</code> if </p>
<p class="formulaDsp">
<img class="formulaDsp" alt="\[ A v = d v. \]" src="form_152.png"/>
</p>
<p> This decomposition can be written in matrix form as </p>
<p class="formulaDsp">
<img class="formulaDsp" alt="\[ A V = V D \]" src="form_153.png"/>
</p>
<p> where </p>
<p class="formulaDsp">
<img class="formulaDsp" alt="\[ V = [v_1,v_2,\ldots,v_n], D = \mathrm{diag}(d_1,d_2,\ldots,d_n). \]" src="form_154.png"/>
</p>
<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.</p>
<p>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.</p>
<p>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>
<p class="formulaDsp">
<img class="formulaDsp" alt="\[ A v = d B v, \]" src="form_155.png"/>
</p>
<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>
<p class="formulaDsp">
<img class="formulaDsp" alt="\[ A V = B V D \]" src="form_156.png"/>
</p>
<p> where </p>
<p class="formulaDsp">
<img class="formulaDsp" alt="\[ V = [v_1,v_2,\ldots,v_n], D = \mathrm{diag}(d_1,d_2,\ldots,d_n). \]" src="form_154.png"/>
</p>
<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. </p>
<h1><a class="anchor" id="Example"></a>
Example</h1>
<p>Some examples of eigenvalue decompositions. First, for a diagonal matrix, the eigenvalues are the diagonal elements of the matrix.</p>
<pre class="fragment">--&gt; A = diag([1.02f,3.04f,1.53f])

A = 
    1.0200         0         0 
         0    3.0400         0 
         0         0    1.5300 

--&gt; 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.</p>
<pre class="fragment">--&gt; 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 

--&gt; 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</p>
<pre class="fragment">--&gt; A = float(randn(2))

A = 
    0.3747   -1.5129 
   -0.6283   -1.1096 

--&gt; [V,D] = eig(A)
V = 
    0.9526    0.6096 
   -0.3042    0.7927 

D = 
    0.8578         0 
         0   -1.5928 

--&gt; A*V - V*D

ans = 

   1.0e-08 * 
   -5.9605         0 
   -2.9802         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.</p>
<pre class="fragment">--&gt; 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 

--&gt; [VB,DB] = eig(B)
VB = 
    0.6153   -0.4176   -0.0000   -0.1495 
   -0.7881   -0.3261   -0.0000    0.1316 
   -0.0000   -0.0000    0.0000   -0.9570 
    0.0189    0.8481    1.0000   -0.2110 

DB = 
    5.5616         0         0         0 
         0    1.4384         0         0 
         0         0    1.0000         0 
         0         0         0   -1.0000 

--&gt; B*VB - VB*DB

ans = 
         0         0    0.0000   -0.0000 
         0    0.0000   -0.0000    0.0000 
   -0.0000   -0.0000   -0.0000   -0.0000 
    0.0000    0.0000    0.0000   -0.5088 

--&gt; [VN,DN] = eig(B,'nobalance')
VN = 
    0.6153   -0.4176   -0.0000   -0.1528 
   -0.7881   -0.3261         0    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 

--&gt; B*VN - VN*DN

ans = 

   1.0e-15 * 
   -1.7764   -0.1110   -0.5587   -0.1665 
    3.5527    1.0547    0.3364   -0.1943 
    0.0172    0.0015    0.0066         0 
    0.1527   -0.2220    0.2220    0.0833 
</pre> </div></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="index.html">FreeMat Documentation</a></li><li class="navelem"><a class="el" href="sec_transforms.html">Transforms/Decompositions</a></li>
    <li class="footer">Generated on Thu Jul 25 2013 17:18:29 for FreeMat by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.1.1 </li>
  </ul>
</div>
</body>
</html>