Professional Documents
Culture Documents
Lec-2
Contents
Matrices Contd
Matrix Indexing
Functions
1. Scalars
2. Vectors
Identity Matrix
zeros
A matrix of zeros
ones
A matrix of ones
diag
rand
Random matrix
MATLAB Functions
rand(3)
rand(3,4)
Matrix of zeros
Zeros(2,3)
Matrix of ones
Ones(10,1)
Identity matrix
Eye(3)
Diagonal matrix
diag(3,2)
Matrix Indexing
Advanced Indexing
Submatrices
A=rand(5)
% Define Matrix
A (2 , 3)
Specifying an element
Column
Row
A(1,end)
A(1:2 , 2:3)
A(1 , :)
A(7)
Specifying contiguous
submatrix
Scalar Functions
Some MATLAB functions applied to:
a. Scalars only
b. To all elements of vectors and matrices
A=rand(3,4)
b=sqrt(A)
C=cos(A)
Vector Functions
Some MATLAB functions that operate on vectors only
Matrix Functions
Important Matrix Functions
A=rand(3)
B=eig(A)
Sometimes such functions may use more than one
output function
[V,D]=eig(A)
Matrix Operations
Matrix Addition
C=A+B
Matrix Subtraction
C=A-B
Matrix mutiplication
C=A*D
Operators
Some relation operators
Logical Operators
Operators Precedence
Plotting
For 2D plots
Exercise