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.

3.6 Using Built-in Functions and On-line Help<br />

89<br />

As shown in Fig. 3.7, <strong>MATLAB</strong> lists all functions that have the string eigenvalue<br />

either in their name or in the first line of their description. You can then browse<br />

through the list, choose the function that seems closest to your needs, and ask for<br />

further help on it. In Fig. 3.7, for example, we seek help on function eig. The<br />

on-line help on eig tells us what this function does and how to use it.<br />

Thus, if we are interested in just the eigenvalues of matrix A, we type eig (A) to<br />

get the eigenvalues, but if we want to find both the eigenvalues and the eigenvectors<br />

of A, we specify the output list explicitly and type [eigvec, eigval] =eig(A) (see<br />

Fig. 3.8) . The names of the output or the input variables can be anything we choose.<br />

Although it's obvious, we note that the list of the variables (input or output) must<br />

be in the same order as specified <strong>by</strong> the function.<br />

>> A = [5 -3 2; -3 8 4; 4 2 -9} ;<br />

» eig (A)<br />

ans =<br />

-10 .2206<br />

4.4 246<br />

9.7960<br />

>> [eigvec ,eigval]<br />

eigve c =<br />

0.1725<br />

0.2 382<br />

-0 . 9558<br />

0.8706<br />

0.3774<br />

0.3156<br />

eig (A)<br />

-<br />

0 . 5375<br />

0. 8429<br />

Typing eig (A) without a list of<br />

outputs gives the eigenvalues of A<br />

in a column vector stored in the<br />

default output variable ans.<br />

Specifying an explicit list of output<br />

variables [eigvec , eigval) gets<br />

the eigenvectors of A in the matrix<br />

eigvec and the eigenvalues of A on<br />

the diagonal of the matrix eigval.<br />

eigval =<br />

-10 .2206<br />

0<br />

0<br />

0<br />

4.4246<br />

0<br />

0<br />

0<br />

9. 7960<br />

Figure 3.8: Examples of usc of the function eig to find eigenvalues and eigenvectors<br />

of a matrix.<br />

Some comments on the help facility<br />

• <strong>MATLAB</strong> is case-sensitive. All built-in functions in <strong>MATLAB</strong> use lowercase<br />

letters for their names, yet the help on any function lists the function in<br />

uppercase letters, as is evident from Figs. 3.5 and 3.7. For the first-time user,

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

Saved successfully!

Ooh no, something went wrong!