You are on page 1of 24

Structural Analysis

Lec-2

Contents
Matrices Contd
Matrix Indexing
Functions
1. Scalars
2. Vectors

Operators (Relation + Logical)


Plotting

Some useful Matrices


eye

Identity Matrix

zeros

A matrix of zeros

ones

A matrix of ones

diag

Creating or extracting diagonals

rand

Random matrix

MATLAB Functions

Some Predefined Matrices


Random matrices

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

To specify entire first row


=A(2,2)

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)

Note: We may extract a submatrix and then use these


functions

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 whose columns are eigen vectors

Matrix whose diagonal values represents eigen values

Matrix Operations
Matrix Addition

C=A+B

Matrix Subtraction

C=A-B

Matrix mutiplication

C=A*D

Operators
Some relation operators

Logical Operators

The result is either 0 or 1.


Zeroif it is false
OneIf it is true

Operators Precedence

Plotting
For 2D plots

For 3D plots.use Plot3

Exercise

You might also like