Lecture 2 Vectors Metrices
Lecture 2 Vectors Metrices
APPROPRIATE SOFTWARE
AMAT 21262
Department of Mathematics
UoK
16.05.2024
OUTLINE
Matrix Concatenation
SCALAR, VECTOR (RAW / COLUMN), MATRIX
A row vector can be created in many ways. First, the most direct way is putting the
desired values in a square bracket.
HOW TO CREATE VECTORS IN MATLAB?
For the regularly spaced vectors, the colon operator can be used to iterate through the
values. The syntax is
The third way of creating a row vector is using function linspace. The syntax is
linspace(x,y,n). This creates a vector with 𝑛 values in the inclusive range
from 𝑥 to 𝑦.
HOW TO CREATE VECTORS IN MATLAB?
Column Vectors
HOW TO CREATE METRIX IN MATLAB?
1 2 3
A=
4 5 6
HOW TO CREATE METRIX IN MATLAB?
3 6 9
Let’s create 𝐵 =
2 6 10
Creating Vectors and Matrices in MATLAB using built-in
functions(Special Matrices)
• The size() function returns the number of rows and columns of a matrix.
v = [16 5 9 4 2 11 7 14]
ans =9
ans =16 2 11
Accessing/Modifying Vector and Matrix Elements cont.
v = [16 5 9 4 2 11 7 14]
• To extract the third through the seventh elements v(3:7)
ans =
9 4 2 11 7
ans =
14
Accessing/Modifying Vector and Matrix Elements cont.
A=
1 2 3 4
5 6 7 8
9 10 11 12
ans =
8
ans =
9 10 11 12
Accessing/Modifying Vector and Matrix Elements cont.
• To extract last column
A(:,end) 1 2 3 4
5 6 7 8
ans = 9 10 11 12
4
8
12
ans =
9
10
11
12
Vector and Matrix Manipulation
1 2 3 4
5 6 7 8
9 10 11 12
1 3 4
5 7 8
9 11 12
Vector and Matrix Manipulation Cont.
1 1 2
3 4 7
8 2 4
B(1,:)=[]
B=
3 4 7
8 2 4
Vector and Matrix Manipulation Cont.
Let’s consider the following matrix C
C=
1 2 3
4 5 6
• To add a row that contains elements 7 8 9 at the end of the matrix C (or to append a row at
the end)
B=
7 8 9
C=[C;B]
C=
1 2 3
4 5 6
7 8 9
Changing Dimensions of Matrices
reshape()
fliplr()
flipud()
rot()
reshape()-changes dimension of the matrix
fliplr()-flip the matrix from left to right
flipud()-flip the matrix from up to down
rot90()-rotates the matrix counter clockwise 90 degrees.
COMPUTATIONS ON VECTORS AND
MATRICES
Adding/ Subtracting Vectors
Multiplying Vectors
• etc,
2𝑥 + 3𝑦 + 4𝑧 = 5
−3𝑥 + 5𝑦 + 3𝑧 = 9
8𝑥 + 4𝑦 + 2𝑧 = −4
𝒙 -3 -2 -1 0 1 2 3
𝑦 = 𝑥2 9 4 1 0 1 4 9