Matrix-Vector Product, Matrix
Download
Report
Transcript Matrix-Vector Product, Matrix
Lecture 7:
Matrix-Vector Product; Matrix of a Linear
Transformation; Matrix-Matrix Product
Sections 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 ndimensional 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 realvalued 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
5 1 2
A 1 3 7
2 7 8
Upper Triangular
a11 a12
A a22
Diagonal
a11
A a22
a33
Lower Triangular
a13
a23
a33
a11
A a21 a22
a31 a32
Identity
1
A 1
1
Banded
a33
a11 a12
a
a
A 21 22
a32
a23
a33
a43
a34
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
1
3
10
2 1 3 1 4 7
4 0 5 8 3 2 12 3 3
2 1 3 1
4 0 5 8
1
2 1 3
4 0 5 4
7
4 7 3 5 4
3 2 4 3 7
8
is not defined.
3
2
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.
a1 a2
b1
b
an 2 a1b1 a2b2
bn
anbn
Example Multiplying Row to Column
3
2
3
1
2
3
5
7
2 1 3 2
5
3
is not defined.
4 0 2 1 2
5
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.
n
c ij aikbkj
k1
Example Matrix
Multiplication
3 2 0
2 1 3
3 0 2 2 1 2
5 3 1
7
-19
12
0
-5
2
3 2 0
is not defined.
2
1
3
2 1 2
Matlab command: A*B
3 0 2
– no dot multiplication
5 3 1
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 411 111 is the inverse of
3
2
11 11
2 1
3 4 .
1
4
2
1
1
0
11
11
3
2 3 4 0 1
11 11
checks
4
1
2 1 11
11 1 0
3 4 3
0
1
2
11 11
checks
Representing Linear Algebra
• Matrices provide a concise notation for
representing and solving simultaneous linear
equations:
a11 a12
a21 a22
a31 a32
a11x1 a12 x 2 a13 x 3 b1
a21x1 a22 x 2 a23 x 3 b2
a31x1 a32 x 2 a33 x 3 b3
a13 x1 b1
a23x 2 b2
a33
x 3 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 x 4 y 2
3x 7 y 7.
The matrix form of the equation is
2 4 x 2
3 7 y 7 .
7 2
x 2 4 2 2 2 7
y 3 7 7 3
1 7 4
2
1
Solving With MATLAB
• MATLAB provides two direct ways to solve
systems of linear algebraic equations
[A]{x}={b}:
▫ Left-division
x = A\b
▫ Matrix inversion
x = 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
n
yi aij x j
j 1
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.
Example
2
9
3 1 1
2 1 5 1 15
4
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:
a c x
n
j 1
ij
1
(1)
j
c2 x j
( 2)
n
n
(1)
( 2)
c1 aij x j c2 aij x j
j 1
j 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
1 and
Au
4
then
11
A(u - 2v)
8
5
Av
2
Example
• The linear transformation represented by the matrix
0
0
A
1
0
is such that
0
0
0
1
1
0
0
0
0
1
0
0
x1 x3
x x
A 2 4
x3 x1
x4 x2
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
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
a 0
0 a aI
which accomplsihes this. (Note: I is the identity matrix.)
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,
n
yi aij x j
j 1
and thus y = A(x) is also given by y = Ax
Example
• If the linear transformation A( · ): R3 → R3 is such that
1
A
0
0
3 0
- 1, A 1
0
0
0
- 1
5 , andA 0
1
4
then the matrix A of A(·) is given by
3 1 1
A 1 5 1
0 4 1
1
- 1
1
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
1 1
0 0
A , A
0 0
1 0
so
1 0
A
0 0
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
1 3 / 2 0 1 / 2
B
, B
0
1 / 2 1 3 / 2
so
3 / 2 1 / 2
B
1
/
2
1
/
2
Question: How were these values obtained?
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:
p
( AB)ij aik xkj
k 1
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).
Example
1 2
2 1 4
A
, B 0 3
1 0 1
1 5
6 13
AB
0 7