Chapter 2 EigenValues and EigenVectors
2.1 The MatLab Approach:
We will now discuss certain ways to compute eigenvalues and
eigenvectors for a square matrix in MatLab..
Start by typing help matfun. This will give you a
list of things you can ask help on as you can see below:
>> help matfun
Matrix functions - numerical linear algebra.
Matrix analysis.
norm - Matrix or vector norm.
normest - Estimate the matrix 2-norm.
rank - Matrix rank.
det - Determinant.
trace - Sum of diagonal elements.
null - Null space.
orth - Orthogonalization.
rref - Reduced row echelon form.
subspace - Angle between two subspaces.
Linear equations.
\ and / - Linear equation solution; use "help slash".
inv - Matrix inverse.
cond - Condition number with respect to inversion.
condest - 1-norm condition number estimate.
chol - Cholesky factorization.
cholinc - Incomplete Cholesky factorization.
lu - LU factorization.
luinc - Incomplete LU factorization.
qr - Orthogonal-triangular decomposition.
lsqnonneg - Linear least squares with nonnegativity constraints.
pinv - Pseudoinverse.
lscov - Least squares with known covariance.
Eigenvalues and singular values.
eig - Eigenvalues and eigenvectors.
svd - Singular value decomposition.
gsvd - Generalized ingular value decomposition.
eigs - A few eigenvalues.
svds - A few singular values.
poly - Characteristic polynomial.
polyeig - Polynomial eigenvalue problem.
condeig - Condition number with respect to eigenvalues.
hess - Hessenberg form.
qz - QZ factorization for generalized eigenvalues.
schur - Schur decomposition.
Matrix functions.
expm - Matrix exponential.
logm - Matrix logarithm.
sqrtm - Matrix square root.
funm - Evaluate general matrix function.
Factorization utilities
qrdelete - Delete column from QR factorization.
qrinsert - Insert column in QR factorization.
rsf2csf - Real block diagonal form to complex diagonal form.
cdf2rdf - Complex diagonal form to real block diagonal form.
balance - Diagonal scaling to improve eigenvalue accuracy.
planerot - Given's plane rotation.
cholupdate - rank 1 update to Cholesky factorization.
qrupdate - rank 1 update to QR factorization.
We are interested in the eigenvalue and eigenvector stuff,
so type help eig. This shows us
>> help eig
EIG Eigenvalues and eigenvectors.
E = EIG(X) is a vector containing the eigenvalues of a square
matrix X.
[V,D] = EIG(X) produces a diagonal matrix D of eigenvalues and a
full matrix V whose columns are the corresponding eigenvectors so
that X*V = V*D.
[V,D] = EIG(X,'nobalance') performs the computation with balancing
disabled, which sometimes gives more accurate results for certain
problems with unusual scaling.
E = EIG(A,B) is a vector containing the generalized eigenvalues
of square matrices A and B.
[V,D] = EIG(A,B) produces a diagonal matrix D of generalized
eigenvalues and a full matrix V whose columns are the
corresponding eigenvectors so that A*V = B*V*D.
See also CONDEIG, EIGS.
Overloaded methods
help lti/eig.m
help sym/eig.m
>>
2.2 Finding Eigenvalues and Eigenvectors:
Let's find these things from the command line: the one thing that
is truly horrible is that the help files list the
matlab functions in capital letters, but you need to use the
real name of the function which might not be in caps.
For example, the function EIG in the help file is
actually the function eig is use. Go figure!
>> A = [1 2 3; 4 5 6; 7 8 -1]
A =
1 2 3
4 5 6
7 8 -1
>> E = eig(A)
E =
-0.3954
11.8161
-6.4206
>>
So we have found the eigenvalues of this small 3 × 3 matrix.
To get the eigenvectors, we do this:
>> [V,D] = eig(A)
V =
0.7530 -0.3054 -0.2580
-0.6525 -0.7238 -0.3770
0.0847 -0.6187 0.8896
D =
-0.3954 0 0
0 11.8161 0
0 0 -6.4206
Note the eigenvalues are not returned in ranked order.
The eigenvalue/ eigenvector pairs are thus
2.3 Symmetric Arrays:
Let's try a nice 5 × 5 array that is symmetric:
>> B = [1 2 3 4 5;
2 5 6 7 9;
3 6 1 2 3;
4 7 2 8 9;
5 9 3 9 6]
B =
1 2 3 4 5
2 5 6 7 9
3 6 1 2 3
4 7 2 8 9
5 9 3 9 6
>> [W,Z] = eig(B)
W =
0.8757 0.0181 -0.0389 0.4023 0.2637
-0.4289 -0.4216 -0.0846 0.6134 0.5049
0.1804 -0.6752 0.4567 -0.4866 0.2571
-0.1283 0.5964 0.5736 -0.0489 0.5445
0.0163 0.1019 -0.6736 -0.4720 0.5594
Z =
0.1454 0 0 0 0
0 2.4465 0 0 0
0 0 -2.2795 0 0
0 0 0 -5.9321 0
0 0 0 0 26.6197
Our theory tells us that the eigenvalues of a symmetric matrix
are real and distinct eigenvectors are orthogonal.
Let's check it out: first, let's find out how to do a
dot product:
>> help dot
DOT Vector dot product.
C = DOT(A,B) returns the scalar product of the vectors A and B.
A and B must be vectors of the same length. When A and B are both
column vectors, DOT(A,B) is the same as A'*B.
DOT(A,B), for N-D arrays A and B, returns the scalar product
along the first non-singleton dimension of A and B. A and B must
have the same size.
DOT(A,B,DIM) returns the scalar product of A and B in the
dimension DIM.
See also CROSS.
So column 1 and column 2 should be orthogonal. We can check this
out:
>> C = dot(W(1:5,1),W(1:5,2))
C =
1.3336e-16
>>
Now, the dot product is not actually 0 because we
are dealing with floating point numbers here, but as you
can see it is close to machine zero.