Professional Documents
Culture Documents
Work
space
Current window
directo Prompt: means the
ry Matlab is ready to
window accept command
following the
prompt. Command
history
window
Command window :
Enter the Matlab statements after the
prompt “>>”
Undocking of windows
Variables may
also be observed
here.
>> clear
a
Variable “a” is
gone.
>> clear
all
Source code of
the command
“polar”
Useful command –
‘demo’
lCommand “demo” will open the demonstration window, from where the
user may find help on topics in animation.
Adding path to Matlab
Whenever Matlab receives a command, it checks in the
following order whether the command is:
•A variable
•A built-in function
•A Matlab source code filename in the current folder
•A Matlab source code filename in other folders
listed in the environment variable “path”.
•
The user may want to add directory of more folders,
where there are Matlab source code file generated
by the user, to the Matlab environment variable
“path” such that the Matlab has access to the
source code files in those folders for later use.
Adding path to Matlab
Use command “path” to view the path of the folders
Adding path to Matlab
To add path to Matlab for source file search, the
user may:
•Use command “ path(path, ‘path to append’) ”
Adding path to Matlab
To add path to Matlab for source file search, the
user may change from the file menu:
•File Set Path
Types of commonly used data and
their derivatives
lCommonly used type of data
ØReal numbers: pi, 1.0, sqrt(2), …
uComplex numbers: 4+i, 5+3i,
ØCharacter / string: ‘YZU’, ‘a’
lEach data is stored as a matrix in Matlab.
Construction of
vector
Construction of a vector
lConstruct a vector with command
“linspace”:
linspace(init, end, number of point)
Operation on vector
elements
>> s = [1 3 5 2]; % use [] for construction of a vector , separate the
elements with % either a comma ‘ , ’ or a space
>> t = 2*s+1
t =
3 7 11 5
mat2(2,4) = mat2(14)
Operation on matrix – change value of
elements
ØChange value of elements in the matrix – assign value
directly or by operation on elements
Exchange of the
1st and the 4th
rows
Operation on matrix – information of
matrix
Øsize: find out the dimension of the matrix
Øndims: number of dimension (rank) of the matrix
rank of mat2 is 2 (2
indices)
Operation on matrix –
transpose
ØTranspose of a matrix:
üAdd the apostrophe symbol “ ‘ “ after
the matrix
üUse command ‘transpose’
Operation on matrix –
transpose
Complex conjugate has
been applied upon the
elements
Element-by-element product
Operation on matrix –
inverse
ØCommand “inv” calculates the inverse of
matrices
Operation on matrix – diagonal
elements
ØCommand “diag” extracts the diagonal elements of
matrices
Operation on matrix – eigenvalue
and characteristic polynomial
ØCommand “eig ( A ) ” calculates the eigenvalues of matrix A
ØCommand “round(poly(A))” returns the characteristic polynomial of
matrix A
Eigenvalues of matrix A
are the roots of the
characteristic polynomial
of matrix A
Operation on matrix – display of
characteristic polynomial
ØDisplay the characteristic polynomial with
variable ‘s’