Matlabnoteschap 02
Matlabnoteschap 02
Topics Covered:
• Vectors
• Definition
• Addition
• Multiplication
• Scalar, Dot, Cross
• Matrices
• Row, Column, Square
• Transpose
• Addition
• Multiplication
• Scalar-Matrix, Matrix-Matrix
• Element-by-Element Operations
• Multiplication, Division, Exponentiation, Vectorized Functions
• Array Addressing
Vectors
𝑎 = 𝑎𝑥 𝑖 + 𝑎𝑦 𝑗 + 𝑎𝑧 𝑘
𝑎 + 𝑏 = 𝑎𝑥 , 𝑎𝑦 , 𝑎𝑧 + 𝑏𝑥 , 𝑏𝑦 , 𝑏𝑧
𝑖 𝑗 𝑘
Determinant
𝑎 × 𝑏 = − 𝑏 × 𝑎 = 𝑎𝑥 𝑎𝑦 𝑎𝑧
Method
𝑏𝑥 𝑏𝑦 𝑏𝑧
𝑎 × 𝑏 = 𝑎𝑦 𝑏𝑧 − 𝑎𝑧 𝑏𝑦 𝑖 − 𝑎𝑥 𝑏𝑧 − 𝑎𝑧 𝑏𝑥 𝑗 + 𝑎𝑥 𝑏𝑦 − 𝑎𝑦 𝑏𝑥 𝑘
Modify and run the Script File as follows:
Matrices
Column 1
𝐶11
𝐂 = 𝐶21
𝐶31
𝐷11 𝐷12
𝐃=
𝐷21 𝐷22
A Vector can be Transposed by switching the Rows and Columns.
3 × 2 × 2 × 3 = (3 × 3)
Outer Sizes
𝐾11 𝐾12
𝐿11 𝐿12 𝐿13
𝐊 × 𝐋 = 𝐾21 𝐾22 ×
𝐿21 𝐿22 𝐿23
𝐾31 𝐾32
𝐾11 𝐿11 + 𝐾12 𝐿21 𝐾11 𝐿12 + 𝐾12 𝐿22 𝐾11 𝐿13 + 𝐾12 𝐿23
= 𝐾21 𝐿11 + 𝐾22 𝐿21 𝐾21 𝐿12 + 𝐾22 𝐿22 𝐾21 𝐿13 + 𝐾22 𝐿23
𝐾31 𝐿11 + 𝐾32 𝐿21 𝐾31 𝐿12 + 𝐾32 𝐿22 𝐾31 𝐿13 + 𝐾32 𝐿23
Modify and run the Script File as follows:
𝐾11 𝐾12
𝐿11 𝐿12 𝐿13
𝐋×𝐊= × 𝐾21 𝐾22
𝐿21 𝐿22 𝐿23
𝐾31 𝐾32
𝐿11 𝐾11 + 𝐿12 𝐾21 + 𝐿13 𝐾31 𝐿11 𝐾12 + 𝐿12 𝐾22 + 𝐿13 𝐾32
=
𝐿21 𝐾11 + 𝐿22 𝐾21 + 𝐿23 𝐾31 𝐿21 𝐾12 + 𝐿22 𝐾22 + 𝐿23 𝐾32
In General,
Inner Sizes Must be Equal
𝑛 × 𝑚 × 𝑚 × 𝑝 = (𝑛 × 𝑝)
𝐶11
𝐁 ∙ 𝐂 = 𝐵11 𝐵12 𝐵13 ∗ 𝐶21
𝐶31
Let:
𝐁 = 1, 2, 3
𝐂 = 4, 5, 6
E𝐥𝐞𝐦𝐞𝐧𝐭 × E𝐥𝐞𝐦𝐞𝐧𝐭 Multiplication:
Element-by-Element Multiplication is often
used in engineering calculations. It is
defined only for arrays that have the same
size.
𝐷11 𝐷12 𝐹11 𝐹12
𝐃.× 𝐅 = .∗
𝐷21 𝐷22 𝐹21 𝐹22
Δx
28 − 5
∆𝑥 = = 11.5
3−1
5 + 11.5 = 16.5
16.5 + 11.5 = 28
𝑥max − 𝑥min
In General, ∆𝑥 =
𝑛−1
Problem 2.1:
a. Use two methods to create the vector x having 100 regularly spaced
values starting at 5 and ending at 28.
b. Use two methods to create the vector x having a regular spacing of
0.2 starting at 2 and ending at 14.