Post on 23-Dec-2015
Lecture 7:Matrix-Vector Product; Matrix of a Linear Transformation; Matrix-Matrix ProductSections 2.1, 2.2.1, 2.2.2
Key Points• The matrix-vector product Ax, where A is a m × n matrix and x is a n-
dimensional column vector, is computed by taking the dot product of each row of A with x. The result is a m-dimensional column vector.
• For a fixed matrix A, the product A x is linear in x:
A(c1x(1) + c2x(2))= c1 A x(1) + c2Ax(2)
• In other words, A acts as a linear transformation, or linear system, which maps n-dimensional vectors to m-dimensional ones.
• Every linear transformation, or linear system, Rn → Rm has a m × n matrix A associated with it. Each column of A is obtained by applying that transformation to the respective standard n-dimensional unit vector.
• If A is m × p and B is p × n, then the product A B is a m × n matrix whose (i, j)th element is the dot product of the ith row of A and the jth column of B.
Review• A m × n matrix consists of entries (or elements) aij, where i and j
are the row and column indices, respectively. The space of all real-valued m × n matrices is denoted by Rm×n .
• A column vector is a matrix consisting of one column only; a row vector is a matrix consisting of one row only. The transpose operator ·T converts row vectors to column vectors and vice versa. By default, a lower-case boldface letter such as a corresponds to a column vector. In situations where the orientation (row or column) of a vector is immaterial, we simply write
a =(a1,...,an)
which is a vector in Rn . • The sum S = A + B of two matrices of the same dimension is
obtained by adding respective entries together: sij = aij + bij
• The matrix cA, where c is a real number, has the same dimensions as A and is obtained by scaling each entry of A by c
Overview
•Matrix:▫rectangular array of elements represented
by a single symbol (e.g. [A]).•Element
▫An individual entry of a matrix▫example: a23 – arow column
Overview (cont)• A horizontal set of elements is called a row and a
vertical set of elements is called a column.
• The first subscript of an element indicates the row while the second indicates the column.
• The size of a matrix is given as m rows by n columns, or simply m by n (or m x n).
• 1 x n matrices are row vectors.
• m x 1 matrices are column vectors.
Special Matrices• Matrices where m=n are called square matrices.• There are a number of special forms of square
matrices:
Symmetric
A 5 1 2
1 3 7
2 7 8
Diagonal
A a11
a22
a33
Identity
A 1
1
1
Upper Triangular
A a11 a12 a13
a22 a23
a33
Lower Triangular
A a11
a21 a22
a31 a32 a33
Banded
A
a11 a12
a21 a22 a23
a32 a33 a34
a43 a44
Matrix Operations• Equal Matrices
▫ Two matrices are considered equal if and only if every element in the first matrix is equal to every corresponding element in the second.
▫ Both matrices must be the same size.
• Matrix addition and subtraction▫ performed by adding or subtracting the corresponding
elements. ▫ Matrices must be the same size.
Example Addition & Subtraction
2 1 3 1 4 7
4 0 5 8 3 2
1 3 10
12 3 3
1 82 1 3
4 34 0 5
7 2
2 1 3 1 4 7
4 0 5 8 3 2
3 5 4
4 3 7
is not defined.
Matrix Multiplication• Scalar matrix multiplication is performed by multiplying
each element by the same scalar.
• If A is a row matrix and B is a column matrix, then we can form the product AB provided that the two matrices have the same length.
• The product AB is a 1x1 matrix obtained by multiplying corresponding entries of A and B and then forming the sum.
1
21 2 1 1 2 2n n n
n
b
ba a a a b a b a b
b
Example Multiplying Row to Column
3
2 1 3 2
5
2 3 1 2 3 5 7
3
4 0 2 1 2
5
is not defined.
Matrix Multiplication
• If A is an mxn matrix and B is an nxq matrix, then we can form the product AB.
• The product AB is an mxq matrix whose entries are obtained by multiplying the rows of A by the columns of B.
• The entry in the ith row and jth column of the product AB is formed by multiplying the ith row of A and jth column of B.
c ij aikbkjk1
n
Example Matrix Multiplication
7 12 -5
-19 0 2
3 2 02 1 3
2 1 23 0 2
5 3 1
is not defined.
3 2 02 1 3
2 1 23 0 2
5 3 1
Matlab command: A*B – no dot multiplication
Matrix Inverse and Transpose
• The inverse of a square matrix A, denoted by A-1, is a square matrix with the property
A-1A = AA-1 = I,where I is an identity matrix of the same size. ▫ Matlab command: inv(A), A^-1
• The transpose of a matrix involves transforming its rows into columns and its columns into rows.▫ (aij)T=aji
▫ Matlab command: a’ or transpose(a)
Example
Verify that is the inverse of 4 111 113 211 11
2 1.
3 4
4 1 2 1 1 011 113 3 4 0 1211 11
4 12 1 1 011 1133 4 0 1211 11
checks
checks
Representing Linear Algebra•Matrices provide a concise notation for
representing and solving simultaneous linear equations:
a11x1 a12x2 a13x3 b1
a21x1 a22x2 a23x3 b2
a31x1 a32x2 a33x3 b3
a11 a12 a13
a21 a22 a23
a31 a32 a33
x1
x2
x3
b1
b2
b3
[A]{x} {b}
Solving a Matrix Equation
Solving a Matrix Equation ▫ If the matrix A has an inverse, then the solution of the matrix
equation
AX = B is given by X = A-1B.
Example Solving a Matrix Equation
Use a matrix equation to solve 2 4 2
3 7 7.
x y
x y
The matrix form of the equation is
2 4 2.
3 7 7
x
y
1 7 22 4 2 2 72
3 7 7 3 7 412
x
y
Solving With MATLAB•MATLAB provides two direct ways to solve
systems of linear algebraic equations [A]{x}={b}:▫Left-divisionx = A\b
▫Matrix inversionx = inv(A)*b
•Disadvantages of the matrix inverse method:▫less efficient than left-division ▫only works for square, non-singular systems.
Matrix-Vector Multiplication• If A is a m × n matrix and x is a n × 1 (column)
vector, then y = Ax
• is an m × 1 vector such that
In other words, the ith entry of y is the dot product of the ith row of A with x.
• We will also view the product y = Ax as a linear combination of the columns of A with coefficients given by the (respective) entries of x.
n
jjiji xay
1
Example
15
9
4
1
2
512
113
Superposition Property• A vector of the form
c1x(1) + c2x(2)
where c1 and c2 are scalars, is known as a linear combination of the vectors x(1) and x(2).
For a fixed matrix A, the product Ax is linear in x, i.e., it has the property that
A(c1x(1) + c2x(2))= c1 A x(1) + c2Ax(2)
for any vectors x(1), x(2) and scalars c1, c2. This is known as the superposition property, and is easily proved by considering the ith entry on each side:
n
jjij
n
jjij
n
jjjij xacxacxcxca
1
)2(2
1
)1(1
1
)2(2
)1(1
Linear Transformation
• An m × n matrix A represents a linear transformation of Rn to Rm . Such a linear transformation is also referred to as a linear system with n-dimensional input vector x and m-dimensional output vector y:
Example• Suppose the 2 × n matrix A and the n-
dimensional column vectors u and v are such that
and
then
4
1Au
2
5Av
8
112v)-A(u
Example• The linear transformation represented by the matrix
is such that
Thus the effect of applying A to an arbitrary vector x is to shift the entries of x up (or down) by two positions in a circular fashion. This linear transformation is an example of a permutation, and all permutations are linear
0010
0001
1000
0100
A
2
1
4
3
4
3
2
1
x
x
x
x
x
x
x
x
A
Extra Credit Activity• You are given an image whose dimensions match
those of a 36 inch (diagonal) display with an aspect ratio of 16 (horizontal) to 9 (vertical). You want to display the image on a 27 inch (diagonal) display with an aspect ratio of 4 (horizontal) to 3 (vertical) such that the image is as large as possible without distortion or cropping. Find the matrix
which accomplsihes this. (Note: I is the identity matrix.)
Iaa
a
0
0
Example• Conversely, every linear transformation A : Rn → Rm has an m × n
matrix associated with it. This can be seen by expressing an arbitrary input vector x as a linear combination of the standard unit vectors:
x = x1 e(1) + . . . + xn e(n)
• By linearity of A( · ), the output vector y = A(x) is given by:y = x1 Ae(1) + . . . + xn Ae(n)
• If we form an m × n matrix A =[aij] using A(e(1)),...,A(e(n)) as its columns (in that order), then the output vector y (above) is, in effect, a linear combination of the columns of A with coefficients x1,...,xn. In other words,
and thus y = A(x) is also given by y = Ax
n
jjiji xay
1
Example• If the linear transformation A( · ): R3 → R3 is such
that
then the matrix A of A(·) is given by
1
1-
1
1
0
0
A
4
5
1-
0
1
0
A
0
1-
3
0
0
1
A and,,
140
151
113
A
Example• Suppose now that A( · ): R2 → R2 represents the projection of
a two-dimensional vector x =(x1,x2) onto the horizontal (i.e., x1) axis. From vector geometry, we know that this is a linear transformation: the projection of a sum of (possibly scaled) vectors is the sum of their projections. We can therefore obtain the matrix A by considering the result of applying A(·) to the two unit vectors (1, 0) and (0, 1). We have
so
01
,00
00A
11A
00
01A
Example• Similarly, the rotation of a two-dimensional vector
through a fixed angle is linear: when two vectors are rotated through the same angle, their (possibly scaled) sum is also rotated through that angle. If B is the matrix representing a counterclockwise rotation by 300, then
so
Question: How were these values obtained?
2/
2/1
1,
2/1
2/
0 3
0B
31B
2/12/1
2/12/3B
Matrix-Matrix Multiplication• If A is m × p and B is p × n, then the product AB
is the m × n matrix whose (i, j)th element is the dot product of the ith row of A and the jth column of B:
The number of columns of A must be the same as the number of rows of B (equal to p in this case, and also referred to as the inner dimension in the product).
p
kkjikij xaAB
1
)(
Example
70
136
51
30
21
,101
412
AB
BA