Você está na página 1de 10

EE263 S. Lall 2011.04.06.

01
Homework 1 Solutions
Due Thursday 4/7.
1. Interpretations of matrix multiplication. 0101
Let B be a 4 4 matrix, to which we apply the following operations:
(i) double column 1,
(ii) halve row 3,
(iii) add row 3 to row 1,
(iv) interchange columns 1 and 4,
(v) subtract row 2 from each of the other rows,
(vi) replace column 4 by column 3,
(vii) delete column 1 (so that the column dimension is reduced by 1)
(a) Write the result as a product of 8 matrices.
(b) Write it again as a product ABC (same B) of three matrices.
Solution.
(a) Each of the operations can be performed as follows.
(a) Double column 1: let B be
B =
_
b
1
b
2
b
3
b
4

where b
i
is a column vector in R
4
. Then postmultiply by a diagonal matrix as
follows.
H =
_
b
1
b
2
b
3
b
4

_
2 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
_

_
. .
W
=
_
2b
1
b
2
b
3
b
4

(b) Halve row 3: let the rows of H be


H =
_

_
h
T
1
h
T
2
h
T
3
h
T
4
_

_
then
J =
_

_
1 0 0 0
0 1 0 0
0 0
1
2
0
0 0 0 1
_

_
. .
P
_

_
h
T
1
h
T
2
h
T
3
h
T
4
_

_
=
_

_
h
T
1
h
T
2
1
2
h
T
3
h
T
4
_

_
(c) Add row 3 to row 1: premultiply J as follows.
K =
_

_
1 0 1 0
0 1 0 0
0 0 1 0
0 0 0 1
_

_
. .
Q
_

_
j
T
1
j
T
2
j
T
3
j
T
4
_

_
=
_

_
j
T
1
+j
T
3
j
T
2
j
T
3
j
T
4
_

_
1
EE263 S. Lall 2011.04.06.01
(d) Interchange column 1 and 4
L =
_
k
1
k
2
k
3
k
4

_
0 0 0 1
0 1 0 0
0 0 1 0
1 0 0 0
_

_
. .
R
=
_
k
4
k
2
k
3
k
1

(e) Subtract row 2 from each of the other rows


M =
_

_
1 1 0 0
0 1 0 0
0 1 1 0
0 1 0 1
_

_
. .
S
_

_
l
T
1
l
T
2
l
T
3
l
T
4
_

_
=
_

_
l
T
1
l
T
2
l
T
2
l
T
3
l
T
2
l
T
4
l
T
2
_

_
(f) Replace column 4 by column 3
N =
_
m
1
m
2
m
3
m
4

_
1 0 0 0
0 1 0 0
0 0 1 1
0 0 0 0
_

_
. .
T
=
_
m
1
m
2
m
3
m
3

(g) Delete column 1 (so that the column dimension is reduced by 1)


A =
_
n
1
n
2
n
3
n
4

_
0 0 0
1 0 0
0 1 0
0 0 1
_

_
. .
U
=
_
n
2
n
3
n
4

Then we have the result as the following product of 8 matrices


A = SQPBWRTU
(b) Write it again as a product ABC (same B) of three matrices.
_

_
1 1
1
2
0
0 1 0 0
0 1
1
2
0
0 1 0 1
_

_
B
_

_
0 0 0
1 0 0
0 1 1
0 0 0
_

_
2. Mass/force example. 42055
Find the matrix A for the mass/force example in the lecture notes. For n = 10, nd a
specic input force sequence x that moves the mass to nal position 1 and nal velocity
zero.
Solution.
Suppose f(t) = f
i
for i 1 t < i and i = 1, 2, 3...10. The key to this problem is to
nd the linear relationship between the forces f
i
and the nal position and velocity (at
t = 10), x(10) and x(10), respectively. In other words, we should nd the 2 10 matrix
A such that
_
x(10)
x(10)
_
= A
_

_
f
1
f
2
f
3
f
4
. . .
f
10
_

_
.
2
EE263 S. Lall 2011.04.06.01
First consider the time interval 0 t < 1. We have
d
2
x
dt
2
= f
1
, x(0) = 0, x(0) = 0.
This dierential equation gives
x(t) = f
1
t, x(t) =
1
2
f
1
t
2
,
so at t = 1 the position and velocity become x(1) =
1
2
f
1
and x(1) = f
1
. Now in the time
interval 1 t < 2
d
2
x
dt
2
= f
2
, x(1) =
1
2
f
1
, x(1) = f
1
,
which gives
x(t) = f
2
(t 1) +f
1
, x(t) =
1
2
f
2
(t 1)
2
+f
1
(t 1) +
1
2
f
1
,
and therefore x(2) =
1
2
f
2
+
3
2
f
1
and x(2) = f
1
+f
2
. For 2 t < 3
d
2
x
dt
2
= f
3
, x(2) =
1
2
f
2
+
3
2
f
1
, x(2) = f
1
+f
2
,
and we get
x(3) = f
1
+f
2
+f
3
x(3) =
5
2
f
1
+
3
2
f
2
+
1
2
f
3
,
Proceeding in the same way we nally have:
_
x(10)
x(10)
_
=
_
1 1 1 1 1 1 1 1 1 1
19
2
17
2
15
2
13
2
11
2
9
2
7
2
5
2
3
2
1
2
_
_

_
f
1
f
2
f
3
f
4
f
5
f
6
f
7
f
8
f
9
f
10
_

_
.
Setting x(10) = 0 and x(10) = 1 gives two linear equations in four unknowns. Therefore,
f
1
, f
2
, f
3
... f
10
cannot be uniquely determined (this is of course intuitively reasonable
since there are many ways to move the mass to nal position 1 and nal velocity zero).
As one example of a possible solution, we may choose to just work with f
1
and f
2
and
set everything else to zero:
f
1
= f
2
= 1, f
i
= 0, 3 i 10.
3. Representing linear functions as matrix multiplication. 42025
Suppose that f : R
n
R
m
is linear. Show that there is a matrix A R
mn
such that
for all x R
n
, f(x) = Ax. (Explicitly describe how you get the coecients A
ij
from
f, and then verify that f(x) = Ax for any x R
n
.) Is the matrix A that represents
f unique? In other words, if

A R
mn
is another matrix such that f(x) =

Ax for
all x R
n
, then do we have

A = A? Either show that this is so, or give an explicit
counterexample.
Solution.
Any x =
_
x
1
x
2
x
n

T
R
n
can be written as
x = x
1
e
1
+x
2
e
2
+ +x
n
e
n
3
EE263 S. Lall 2011.04.06.01
where e
i
is the ith unit vector in R
n
. From linearity of f() we have
f(x) = x
1
f(e
1
) +x
2
f(e
2
) + +x
n
f(e
n
),
or in (block) matrix form
f(x) =
_
f(e
1
) f(e
2
) f(e
n
)

x.
Therefore, we simply take
A :=
_
f(e
1
) f(e
2
) f(e
n
)

.
In other words, we only need the transformations of the unit vectors e
i
to form the matrix
A. Note that f(e
i
) R
m
for i = 1, 2, . . . , n so A becomes an m n matrix. Suppose
the matrix A is not unique and there is another

A R
mn
such that f(x) =

Ax. Then
Ax =

Ax or (A

A)x = 0 for all x R
n
. When x = e
i
, (A

A)e
i
= 0 implies that the
ith column of (A

A) is zero. Repeating this argument for i = 1, 2, . . . , n proves that all
columns of (A

A) are zero and hence A =

A. Therefore the choice of A is unique.
4. Some linear functions associated with a convolution system. 42030
Suppose that u and y are scalar-valued discrete-time signals (i.e., sequences) related via
convolution:
y(k) =

j
h
j
u(k j), k Z,
where h
k
R. You can assume that the convolution is causal, i.e., h
j
= 0 when j < 0.
(a) The input/output (Toeplitz) matrix. Assume that u(k) = 0 for k < 0, and dene
U =
_

_
u(0)
u(1)
.
.
.
u(N)
_

_
, Y =
_

_
y(0)
y(1)
.
.
.
y(N)
_

_
.
Thus U and Y are vectors that give the rst N + 1 values of the input and output
signals, respectively. Find the matrix T such that Y = TU. The matrix T describes
the linear mapping from (a chunk of) the input to (a chunk of) the output. T
is called the input/output or Toeplitz matrix (of size N + 1) associated with the
convolution system.
(b) The Hankel matrix. Now assume that u(k) = 0 for k > 0 or k < N and let
U =
_

_
u(0)
u(1)
.
.
.
u(N)
_

_
, Y =
_

_
y(0)
y(1)
.
.
.
y(N)
_

_
.
Here U gives the past input to the system, and Y gives (a chunk of) the resulting
future output. Find the matrix H such that Y = HU. H is called the Hankel matrix
(of size N + 1) associated with the convolution system.
Solution.
(a) The input/output (Toeplitz) matrix. Since h
j
= 0 for j < 0 and u(k) = 0 for k < 0
we have
y(k) =
k

j=0
h
j
u(k j) =
k

j=0
h
kj
u(j),
4
EE263 S. Lall 2011.04.06.01
so for k = 0, 1, 2, . . . , N
y(0) = h
0
u(0)
y(1) = h
1
u(0) + h
0
u(1)
y(2) = h
2
u(0) + h
1
u(1) + h
0
u(2)
.
.
.
y(N) = h
N
u(0) + h
N1
u(1) + h
N2
u(2) + + h
0
u(N).
These equations can be written in matrix form as
_

_
y(0)
y(1)
y(2)
.
.
.
y(N)
_

_
. .
Y
=
_

_
h
0
0 0 0
h
1
h
0
0 0
h
2
h
1
h
0
0
.
.
.
.
.
.
.
.
.
h
N
h
N1
h
1
h
0
_

_
. .
T
_

_
u(0)
u(1)
u(2)
.
.
.
u(N)
_

_
. .
U
(Note: the matrix T above is such that its (i, j)th entry depends only on the value of
i j. In other words, it is constant along the diagonals. Such matrices are called
Toeplitz matrices.)
(b) The Hankel matrix. Since u(k) = 0 for k > 0 or k < N
y(k) =
N+k

j=k
h
j
u(k j)
so for k = 0, 1, 2, . . . , N
y(0) = h
0
u(0) + h
1
u(1) + + h
N
u(N)
y(1) = h
1
u(0) + h
2
u(1) + + h
N+1
u(N)
y(2) = h
2
u(0) + h
3
u(1) + + h
N+2
u(N)
.
.
.
y(N) = h
N
u(0) + h
N+1
u(1) + + h
N+N
u(N)
and therefore
_

_
y(0)
y(1)
y(2)
.
.
.
y(N)
_

_
. .
Y
=
_

_
h
0
h
1
h
2
h
N
h
1
h
2
h
3
h
N+1
h
2
h
3
h
4
h
N+2
.
.
.
.
.
.
h
N
h
N+1
h
N+2
h
N+N
_

_
. .
H
_

_
u(0)
u(1)
u(2)
.
.
.
u(N)
_

_
. .
U
(Note: matrices such as H above that are constant along the antidiagonals are
called Hankel matrices.
5. Counting sequences in a language or code. 42070
We consider a language or code with an alphabet of n symbols 1, 2, . . . , n. A sentence
is a nite sequence of symbols, k
1
, . . . , k
m
where k
i
{1, . . . , n}. A language or code
consists of a set of sequences, which we will call the allowable sequences. A language is
called Markov if the allowed sequences can be described by giving the allowable transitions
between consecutive symbols. For each symbol we give a set of symbols which are allowed
to follow the symbol. As a simple example, consider a Markov language with three symbols
1, 2, 3. Symbol 1 can be followed by 1 or 3; symbol 2 must be followed by 3; and symbol
3 can be followed by 1 or 2. The sentence 1132313 is allowable (i.e., in the language);
5
EE263 S. Lall 2011.04.06.01
the sentence 1132312 is not allowable (i.e., not in the language). To describe the allowed
symbol transitions we can dene a matrix A R
nn
by
A
ij
=
_
1 if symbol i is allowed to follow symbol j
0 if symbol i is not allowed to follow symbol j
.
(a) Let B = A
k
. Give an interpretation of B
ij
in terms of the language.
(b) Consider the Markov language with ve symbols 1, 2, 3, 4, 5, and the following tran-
sition rules:
1 must be followed by 2 or 3
2 must be followed by 2 or 5
3 must be followed by 1
4 must be followed by 4 or 2 or 5
5 must be followed by 1 or 3
Find the total number of allowed sentences of length 10. Compare this number to
the simple code that consists of all sequences from the alphabet (i.e., all symbol
transitions are allowed). In addition to giving the answer, you must explain how you
solve the problem. Do not hesitate to use Matlab.
Solution.
(a) This problem is similar to, but not quite the same as, the problem on counting paths
of a given length. If B = A
k
, then B
ij
is the number of sequences of length k + 1
that start with symbol j and end with symbol i.
(b) For the given Markov language we can nd the number of allowed sequences of length
10 by simply adding all the entries of the matrix A
9
. Form the description of the
rules we have
A =
_

_
0 0 1 0 1
1 1 0 1 0
1 0 0 0 1
0 0 0 1 0
0 1 0 1 0
_

_
.
Using the Matlab command B = A^9 we nd
B = A
9
=
_

_
41 49 24 113 37
55 65 31 150 49
42 49 23 113 37
0 0 0 1 0
31 37 18 86 28
_

_
.
(Note that there is only one word that ends with 4 (i.e., 4444444444, because 4 can
only follow 4.) Adding all the elements of B, using for example the Matlab command
sum(sum(B)), we nd that the total number of allowed sequences of length 10 is 1079.
Finally, we can compare this number to the simple code that consists of all sequences
from the alphabet. Of course there are 5
10
= 9765625 such sequences. Just to check
our method, we can also compute this number the same way as above, by forming
the matrix
A =
_

_
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
_

_
,
(which means any symbol can follow any symbol), then nd B = A
9
, and adding all
the entries of the matrix B. (Yes, you do get the same number as above . . . )
6
EE263 S. Lall 2011.04.06.01
6. Paths and cycles in a directed graph. 42110
We consider a directed graph with n nodes. The graph is specied by its node adjacency
matrix A R
nn
, dened as
A
ij
=
_
1 if there is an edge from node j to node i
0 otherwise.
Note that the edges are oriented, i.e., A
34
= 1 means there is an edge from node 4 to
node 3. For simplicity we do not allow self-loops, i.e., A
ii
= 0 for all i, 1 i n. A
simple example illustrating this notation is shown below.
1 2
4 3
The node adjacency matrix for this example is
A =
_

_
0 0 0 1
1 0 1 0
0 1 0 0
0 0 1 0
_

_
.
In this example, nodes 2 and 3 are connected in both directions, i.e., there is an edge
from 2 to 3 and also an edge from 3 to 2. A path of length l > 0 from node j to node
i is a sequence s
0
= j, s
1
, . . . , s
l
= i of nodes, with A
s
k+1
,s
k
= 1 for k = 0, 1, . . . , l 1.
For example, in the graph shown above, 1, 2, 3, 2 is a path of length 3. A cycle of length
l is a path of length l, with the same starting and ending node, with no repeated nodes
other than the endpoints. In other words, a cycle is a sequence of nodes of the form
s
0
, s
1
, . . . , s
l1
, s
0
, with
A
s
1
,s
0
= 1, A
s
2
,s
1
= 1, . . . A
s
0
,s
l1
= 1,
and
s
i
= s
j
for i = j, i, j = 0, . . . , l 1.
For example, in the graph shown above, 1, 2, 3, 4, 1 is a cycle of length 4. The rest of this
problem concerns a specic graph, given in the le directed_graph.m on the course web
site. For each of the following questions, you must give the answer explicitly (for example,
enclosed in a box). You must also explain clearly how you arrived at your answer.
(a) What is the length of a shortest cycle? (Shortest means minimum length.)
(b) What is the length of a shortest path from node 13 to node 17? (If there are no
paths from node 13 to node 17, you can give the answer as innity.)
(c) What is the length of a shortest path from node 13 to node 17, that does not pass
through node 3?
(d) What is the length of a shortest path from node 13 to node 17, that does pass
through node 9?
(e) Among all paths of length 10 that start at node 5, nd the most common ending
node.
(f) Among all paths of length 10 that end at node 8, nd the most common starting
node.
7
EE263 S. Lall 2011.04.06.01
(g) Among all paths of length 10, nd the most common pair of starting and ending
nodes. In other words, nd i, j which maximize the number of paths of length 10
from i to j.
Solution.
(a) Recall that (A
k
)
ij
gives the number of paths of length k from node j to node i.
Thus, (A
k
)
ii
is the number of paths of length k from node i to itself. Now imagine
increasing k from k = 1 to k = 2, k = 3, and so on. We nd the smallest k for which
(A
k
)
ii
> 0. This k is the length of the smallest path from i to itself. This path is
in fact also a cycle, since it cannot repeat nodes. (If it repeated nodes, there would
have been a shorter path from i to itself.) Now lets solve the problem. To nd the
length of a shortest cycle, nd the smallest k such that (A
k
)
ii
> 0 for some i. Note
k n, because if a cycle exists then it is at most of length n, where n is the number
of nodes in the graph.
clear all
directed_graph;
sz = size(A);
n = sz(1); % number of nodes
cycle_found = 0;
for k = 1:n
if max(diag(A^k)) > 0
cycle_found = 1;
break;
end
end
if cycle_found == 1
length = k
else
fprintf(Graph contains no cycle.);
end
>>smallest_cycle_length
length = 6
The smallest cycle is of length 6.
(b) To nd the length of a shortest path from node 13 to node 17, nd the smallest k
such that (A
k
)
17,13
> 0.
path_found = 0;
for k = 1:n
Ak = A^k;
if Ak(17,13) > 0
path_found = 1;
break;
end
end
if path_found == 1
length = k
else
fprintf(No path from 13 to 17.)
end
>> shortest_path_13to17
length = 4
The shortest path from node 13 to node 17 is of length 4.
(c) To nd the shortest path from node 13 to node 17, that does not pass though node
3, remove node 3 from the graph and then nd the shortest path from node 13 to
8
EE263 S. Lall 2011.04.06.01
node 17. The new adjacency matrix B for the graph is obtained by removing the 3rd
row and column of the matrix A. Then nd the smallest k such that (B
k
)
17,13
> 0.
B = [A(1:2, 1:2) A(1:2, 4:20);
A(4:20,1:2) A(4:20, 4:20)];
path_found = 0;
for k = 1:n-1
Bk = B^k;
if Bk(16,12)>0
path_found = 1;
break;
end
end
if path_found == 1
length = k
else
fprintf(No path exists.)
end
>> shortest_path_13to17not3
length = 5
The shortest path from node 13 to node 17, that does not pass through node 3 is of
length 5.
(d) To nd the smallest path from node 13 to node 17, that does pass through node 9,
nd the shortest path from node 13 to node 9 and the shortest path from node 9 to
node 17.
path_found = 0;
for k = 1:n
Ak = A^k;
if Ak(9,13) > 0
path_found = 1;
break;
end
end
if path_found == 1
length13to9 = k
else
fprintf(No path exists)
end
if path_found == 1
path_found = 0;
for k = 1:n
Ak = A^k;
if Ak(17,9) > 0
path_found = 1;
break;
end
end
if path_found == 1
length9to17 = k
else
fprintf(No path exists)
end
end
if path_found == 1
length = length13to9+length9to17
9
EE263 S. Lall 2011.04.06.01
end
>> shortest_path_13to17thru9
length13to9 = 6
length9to17 = 4
length = 10
The shortest path from node 13 to node 17, that does pass through node 9 is of
length 10.
(e) The matrix A
10
gives the number of paths of length 10, i.e., (A
10
)
ij
is the number
of paths of length 10 that start at node j and end at node i. The 5th column of
the matrix A
10
gives the number of paths of length 10 that start at node 5 and end
at nodes 1, 2, . . . , 20 respectively. The index of the maximum entry of this column
gives the most common ending node for paths of length 10 starting at node 5.
A10 = A^10;
start5 = A10(1:20,5);
[number, mostcommonendnode] = max(start5);
mostcommonendnode
>>endnode
mostcommonendnode = 5
The most common ending node for paths of length 10 starting at node 5, is 5.
(f) The 8th row of the matrix A
10
gives the number of paths that end at node 8. The
index of the maximum entry of this row gives the most common starting node for
paths of length 10 ending at node 8.
end8 = A10(8,1:20);
[number, mostcommonstartnode] = max(end8);
mostcommonstartnode
>>startnode
mostcommonstartnode = 8
The most common starting node for paths of length 10 ending at node 8, is 8.
(g) The most common source/destination pair for paths of length 10 is the index of the
maximum entry of A
10
, i.e., if (i, j) is the most common source/destination pair
then no other number in the matrix A
10
is greater than (A
10
)
ji
.
[max_row, dests] = max(A10);
[max_e, mostcommonsource] = max(max_row);
mostcommonsource
mostcommondest= dests(mostcommonsource)
>>sdpair
mostcommonsource = 8
mostcommondest = 17
The most common source/destination pair for paths of length 10 is (8, 17).
10

Você também pode gostar