250 likes | 754 Views
EGR 106 – Week 4 – Math on Arrays. Linear algebraic operations: Multiplication Division Row/column based operations Rest of chapter 3. Array Multiplication (Linear Algebra). In linear algebra, the matrix expression F = A * B means
E N D
EGR 106 – Week 4 – Math on Arrays • Linear algebraic operations: • Multiplication • Division • Row/column based operations • Rest of chapter 3
Array Multiplication (Linear Algebra) • In linear algebra, the matrix expression F = A * B means • Entries are dot products of rows of the first matrix with columns of the second = *
a b c d • For example: a1xc1 + b1xc2 a1xd1 + b1xd2
Notes: • The operation is generally not commutative A*B ≠ B*A • The number of columns of the 1stmust match the number of rows of the 2nd = * n by m n by k k by m
For example, here multiplication works both ways, but is not commutative: quite different!
Multiplications F=A*B (2col, 2 rows) • 1x7+2x8 1x9+2x10 1x11+2x12 • 23 29 35 • 3x7+4x8 3x9+4x10 3x11+4x12 • 53 67 81 • 5x7+6x8 5x9+6x10 5x11+6x12 • 83 105 127
Multiplications F=B*A (3cols, 3rows) • 7x1+9x3+11x5 7x2+9x4+11x6 • 89 116 • 8x1+10x3+12x5 8X2+10x4+12x6 • 98 128
(2 cols, 3 rows) • And here it doesn’t work at all:
Application of Multiplication • Application of matrix multiplication: n simultaneous equations in m unknowns (the x’s) n rows, m columns
For example: • In matrix form this isA * x = b with Coefficients
In general: A * x = b • A is n by m • x is m by 1 • b is n by 1 column vectors (lower case)
Usages – finding: cable tensions in statics fluid flow in piping heat flow in thermodynamics e.g. v currents in circuits traffic flow economics R1 R3 R2
Array Division • Recall the command eye(n) • This result is the array multiplication identity matrixI • For any array A A * I = I * A = A must be properly sized!
Imagine that for square arrays A and B we have A * B = B * A = I then we call them inverses A = B–1 B = A–1 • In Matlab: A ^ -1 or inv(A) • When does A–1 exist? • A is square • A has a non-zero determinant (det(A))
For example: (Must be non zero for inv)
Solving A * x = b • Assume that A is square and det(A) ≠ 0 • Multiply both sides by A–1 on the left A–1 *A * x = A–1* b so x = A–1* b • In Matlab, x = A\ b or x = inv(A)*b = I = x backwards slash
9x2+8x3=6 7x1+4x2+5x3=8 4x1+4x2+2x3=0 • For example: • Check your work: x1 x2 x3
Vector Based Operations • Some operations analyze a vector to yield a single value. For example: sums the elements
Other operations for a vector A: • Minimum: min(A) • Maximum: max(A) • Median: median(A) • Mean or average: mean(A) • Standard deviation: std(A) • Product of the elements: prod(A)
Some operators yield two results: • min and max can yield both the valueand its location • default is the first result
Some operators yield vector results • size(A) we’ve already seen • sort
Finally, when applied to an array, these operators perform their action on columns
Unless you instruct it to work on rows! the 2 means “use the 2nd dimension” i.e. spanning the columns