02.03.2016 Views

MATLAB by rudra pratap

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

138 Applications<br />

Step 2: Extract what you need: In the output list, V is an n x n matrix whose<br />

columns are eigenvectors and D is an n x n diagonal matrix that ha."> the<br />

eigenvalues of A on its diagonal. The function eig can also be utied with one<br />

output argument, e.g., lams=eig(A) , in which case the function gives only<br />

the eigenvalues in the vector lams.<br />

After computing the eigenvalues and eigenvectors, you could check a few things<br />

if you wish: Are the eigenvalues and eigenvectors ordered in the output? Check<br />

<strong>by</strong> substituting in eqn. (5.2). For example, let us check the second eigenvalue and<br />

second eigenvector and see if, indeed, they satisfy Av = .\v.<br />

>> v2 = V(:,2 );<br />

>> lam2 = 0(2,2) ;<br />

>> A*v2 - lam2*v2<br />

% extract the second column from V<br />

% extract the second eigenvalue from D<br />

% check the difference between A*v and lambda*v<br />

Here, we have used two commands for clarity. You could, of course, combine<br />

them into one: A*V (: , 2) -D (2, 2) *V (: , 2). Note that the last command may not<br />

result into zero vector, as you expect, but it will have very small numbers.<br />

5.1.4 Matrix factorizations<br />

<strong>MATLAB</strong> provides built-in functions for several matrix factorizations (decompositions):<br />

1. LU factorization: The name of the built-in function is lu. To get the LU<br />

factorization of a square matrix A, type the command<br />

[L ,U] = lu(A) ;<br />

<strong>MATLAB</strong> returns a lower triangular matrix L and an upper triangular matrix<br />

U such that L*U=A. It is also possible to get the permutation matrix as an<br />

output (see the on-line help on lu) .<br />

2. QR factorization: The name of the built-in function is qr. Typing the<br />

command<br />

[Q , R] = qr (A) ;<br />

returns an orthogonal matrix Q and an upper triangular matrix R such that<br />

Q*R=A. For more information, see the on-line help.<br />

3. Cholesky factorization: If you have a positive definite matrix A, you can<br />

factorize the matrix with the built-in function chol. The command<br />

R = chol(A) ;<br />

produces an upper triangular matrix R such that R' *R=A.<br />

4. Singular value decomposition (svd): The name of the built-in function<br />

is svd. If you type<br />

[U ,D,V] = svd(A) ;<br />

<strong>MATLAB</strong> returns two orthogonal matrices, U and V, and a diagonal matrix<br />

D, with the singular values of A as the diagonal entries, such that U*D*V=A.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!