0% found this document useful (0 votes)
0 views38 pages

05 MATLAB Array Operations

The document provides syntax and descriptions for various matrix operations in a programming context, including creating identity, ones, and zeros matrices, as well as generating random matrices. It also covers matrix addition, multiplication, and element-wise operations, along with their respective syntax. Additionally, it includes information on matrix transposition and determinants.

Uploaded by

Reymart Tuna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views38 pages

05 MATLAB Array Operations

The document provides syntax and descriptions for various matrix operations in a programming context, including creating identity, ones, and zeros matrices, as well as generating random matrices. It also covers matrix addition, multiplication, and element-wise operations, along with their respective syntax. Additionally, it includes information on matrix transposition and determinants.

Uploaded by

Reymart Tuna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

1 0 0

0 1 0
0 0 1
SYNTAX DESCRIPTION

eye(n) Returns the n-by-n identity matrix.


eye(m,n) or Returns an m-by-n matrix with 1s on the diagonal
eye([m,n]) and 0s elsewhere. The size inputs m and n should be
nonnegative integers. Negative integers are treated as
0.
eye(size(A)) Returns an identity matrix the same size as A.
1 1 1
1 1 1
1 1 1
SYNTAX DESCRIPTION
X = ones(n) Returns the n-by-n matrix of 1s. An error message
appears if n is not a scalar.
X = ones(m,n) or Returns an m-by-n matrix of 1s
X = ones([m,n])
X =ones(size(A)) Returns a matrix of 1s that is the same size as A.
0 0 0
0 0 0
0 0 0
SYNTAX DESCRIPTION
X = zeros(n) Returns the n-by-n matrix of zeros. An error
message appears if n is not a scalar.
X = zeros(m,n) or Returns an m-by-n matrix of zeros
X = zeros([m,n])
X = zeros(size(A)) Returns a matrix of zeros that is the same size as A.
SYNTAX DESCRIPTION
X = rand(n) Returns the n-by-n matrix containing pseudorandom
values drawn from the standard uniform distribution
on the open interval (0,1).
X = rand(m,n) or Returns an m-by-n matrix containing pseudorandom
X = rand([m,n]) values
X = rand Returns a scalar
X = rand(size(A)) Returns a matrix containing pseudorandom values
that is the same size as A.
SYNTAX DESCRIPTION
X = randn(n) Returns the n-by-n matrix containing pseudorandom
values drawn from the standard normal distribution
on the open interval (0,1).
X = randn(m,n) or Returns an m-by-n matrix containing normal
X = randn([m,n]) pseudorandom values
X = randn(n) Returns a normal scalar
X = randn(size(A)) Returns a matrix containing normal pseudorandom
values that is the same size as A.
Lower Triangular Matrix Upper Triangular Matrix
Syntax: tril(A) Syntax: triu(A)
𝐴 + 𝐵 = 𝑎𝑖𝑗 + 𝑏𝑖𝑗 𝑚×𝑛 Syntax: A+B

Note: Two matrices can only be added if and only if they


have the same sizes.
𝑘𝑎11 𝑘𝑎12 ⋯ 𝑘𝑎1𝑛
𝑘𝑎21 𝑘𝑎22 ⋯ 𝑘𝑎2𝑛
𝑘𝐴 = 𝑘 𝑎𝑖𝑗 = 𝑘𝑎𝑖𝑗 =
𝑚×𝑛 𝑚×𝑛 ⋮ ⋮ ⋮
𝑘𝑎𝑚1 𝑘𝑎𝑚2 ⋯ 𝑘𝑎𝑚𝑛

Syntax: k*B
𝑎11 𝑎12 ⋯ 𝑎1𝑝 𝑏11 𝑏12 ⋯ 𝑏1𝑛
𝑎 𝑎22 ⋯ 𝑎2𝑝 𝑏21 𝑏22 ⋯ 𝑏2𝑛
𝐴𝐵 = 21
⋮ ⋮ ⋮ ⋮ ⋮ ⋮
𝑎𝑚1 𝑎𝑚2 ⋯ 𝑎𝑚𝑝 𝑏𝑝1 𝑏𝑝2 ⋯ 𝑏𝑝𝑛
𝑎11 𝑏11 + 𝑎12 𝑏21 + ⋯ + 𝑎1𝑝 𝑏𝑝1 … 𝑎11 𝑏1𝑛 + 𝑎12 𝑏2𝑛 + ⋯ + 𝑎1𝑝 𝑏𝑝𝑛
𝑎21 𝑏11 + 𝑎22 𝑏21 + ⋯ + 𝑎2𝑝 𝑏𝑝1 ⋯ 𝑎21 𝑏1𝑛 + 𝑎22 𝑏2𝑛 + ⋯ + 𝑎2𝑝 𝑏𝑝𝑛
𝐴𝐵 =

𝑎𝑚1 𝑏11 + 𝑎𝑚2𝑏21 + ⋯ + 𝑎𝑚𝑝 𝑏𝑝1 ⋯ 𝑎𝑚1𝑏1𝑛 + 𝑎𝑚2 𝑏2𝑛 + ⋯ + 𝑎𝑚𝑝 𝑏𝑝𝑛
Size of the Product in the Matrix Multiplication

𝐴𝑚×𝑝 𝐵𝑝×𝑛 = 𝐶𝑚×𝑛


Syntax: A*B
should be EQUAL!
3×2 2×2 3×2

should be EQUAL!
2×2 3×2

should be EQUAL!
⋯ 𝑎1𝑛 𝑇
𝑎11 𝑎12
𝑇 𝑎21 𝑎22 ⋯ 𝑎2𝑛
𝐴 =
⋮ ⋮ ⋮
𝑎𝑚1 𝑎𝑚2 ⋯ 𝑎𝑚𝑛

𝑎11 𝑎21 ⋯ 𝑎𝑚1


𝑇 𝑎12 𝑎22 ⋯ 𝑎𝑚2
𝐴 =
⋮ ⋮ ⋮
𝑎1𝑛 𝑎2𝑛 ⋯ 𝑎𝑚𝑛
Syntax: A’
𝑎11 𝑎12 ⋯ 𝑎1𝑛 𝑏11 𝑏12 ⋯ 𝑏1𝑛 1 0 ⋯ 0
𝑎21 𝑎22 ⋯ 𝑎2𝑛 𝑏21 𝑏22 ⋯ 𝑏2𝑛 0 1 ⋯ 0
=
⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮
𝑎𝑛1 𝑎𝑛2 ⋯ 𝑎𝑛𝑛 𝑏 𝑏𝑛2 ⋯ 𝑏𝑛𝑛 0 0 ⋯ 1
𝑛1

Syntax: inv(A)
Syntax: A*inv(B)
Syntax: A/B
Syntax: 𝑨_𝒔𝒒𝒖𝒂𝒓𝒆 = 𝑨 ∗ 𝑨
Syntax: 𝑨_𝒏𝒕𝒉 = 𝑨^𝒏
𝑎11 𝑎12 ⋯ 𝑎1𝑛 𝑎11 𝑎12 ⋯ 𝑎1𝑛
𝑎21 𝑎22 ⋯ 𝑎2𝑛 𝑎21 𝑎22 ⋯ 𝑎2𝑛
𝐴= det 𝐴 =
⋮ ⋮ ⋮ ⋮ ⋮ ⋮
𝑎𝑛1 𝑎𝑛2 ⋯ 𝑎𝑛𝑛 𝑎𝑛1 𝑎𝑛2 ⋯ 𝑎𝑛𝑛

Syntax: det(A)
Element-Wise
Operation Syntax

Addition +
Multiplication .*
Division ./
Exponentiation .^
1 3 4 0 2 −2 1 5 2
6 7 8 + 1 4 2 = 7 11 10
2 3 −1 1 1 −1 3 4 −2

Syntax: 𝑨 + 𝑩
1 3 4 0 2 −2 0 6 −8
6 7 8 .× 1 4 2 = 6 28 16
2 3 −1 1 1 −1 2 3 1

Syntax: 𝑨.∗ 𝑩
1 3 4 2 2 −2 0.5 1.5 −2
6 7 8 ./ 1 2 2 = 6 3.5 4
2 3 −1 1 1 −1 2 3 1

Syntax: 𝑨./𝑩
.^2
1 3 4 12 32 42 1 9 16
6 7 8 = 62 72 82 = 36 49 64
2 3 −1 22 32 −1 2
4 9 1

Syntax: 𝑨. ^𝟐

You might also like