final exam solutions - ee263.stanford.eduee263.stanford.edu/exams/final20/solutions.pdf · discuss...

31
Introduction to Linear Dynamical Systems EE263, Summer 2020 August 14-15 2020 Final Exam Solutions This is a 12 hour take-home exam with 4 problems. Please turn it in on Gradescope 12 hours after it is emailed to you. You may use any books, notes, or computer programs (e.g., matlab), but you may not discuss the exam with others until August 15, after everyone has taken the exam. The only exception is that you can ask the course staff for clarification, by emailing to the staff email address {gorish, ntragus} @stanford.edu. We’ve tried pretty hard to make the exam unambiguous and clear, so we’re unlikely to say much. Please do not post any exam related questions on Piazza. Since you have 12 hours, we expect your solutions to be legible, neat, and clear. Do not hand in your rough notes, and please try to simplify your solutions as much as you can. We will deduct points from solutions that are technically correct, but much more complicated than they need to be. Please check your email and canvas a few times during the exam, just in case we need to send out a clarification or other announcement. It’s unlikely we’ll need to do this, but you never know. Assemble your solutions to the problems in order, i.e., problem 1, problem 2, problem 3, problem 4. Start each problem on a new page. Please make a copy of your exam before handing it in. We have never lost one, but it might occur. If a problem asks for some specific answers, make sure they are obvious in your solu- tions. You might put a box around the answers, so they stand out from the surrounding discussion, justification, plots, etc. When a problem involves some computation (say, using matlab), we do not want just the final answers. We want a clear discussion and justification of exactly what you did, the matlab source code that produces the result, and the final numerical result. Be sure to show us your verification that your computed solution satisfies whatever properties it is supposed to, at least up to numerical precision. For example, if you compute a vector x that is supposed to satisfy Ax = b (say), show us the matlab code that checks this, and the result. (This might be done by the matlab code norm(A*x-b); be sure to show us the result, which should be very small.) We will not check your numerical solutions for you, in cases where there is more than one solution. 1

Upload: others

Post on 18-Oct-2020

25 views

Category:

Documents


9 download

TRANSCRIPT

Page 1: Final Exam Solutions - ee263.stanford.eduee263.stanford.edu/exams/final20/solutions.pdf · discuss the exam with others until August 15, after everyone has taken the exam. The only

Introduction to Linear Dynamical Systems EE263, Summer 2020August 14-15 2020

Final Exam Solutions

This is a 12 hour take-home exam with 4 problems. Please turn it in on Gradescope 12 hoursafter it is emailed to you.

• You may use any books, notes, or computer programs (e.g., matlab), but you may notdiscuss the exam with others until August 15, after everyone has taken the exam. Theonly exception is that you can ask the course staff for clarification, by emailing to thestaff email address {gorish, ntragus} @stanford.edu. We’ve tried pretty hard tomake the exam unambiguous and clear, so we’re unlikely to say much. Please do notpost any exam related questions on Piazza.

• Since you have 12 hours, we expect your solutions to be legible, neat, and clear. Donot hand in your rough notes, and please try to simplify your solutions as much as youcan. We will deduct points from solutions that are technically correct, but much morecomplicated than they need to be.

• Please check your email and canvas a few times during the exam, just in case we needto send out a clarification or other announcement. It’s unlikely we’ll need to do this,but you never know.

• Assemble your solutions to the problems in order, i.e., problem 1, problem 2, problem3, problem 4. Start each problem on a new page.

• Please make a copy of your exam before handing it in. We have never lost one, but itmight occur.

• If a problem asks for some specific answers, make sure they are obvious in your solu-tions. You might put a box around the answers, so they stand out from the surroundingdiscussion, justification, plots, etc.

• When a problem involves some computation (say, using matlab), we do not want justthe final answers. We want a clear discussion and justification of exactly what you did,the matlab source code that produces the result, and the final numerical result. Be sureto show us your verification that your computed solution satisfies whatever propertiesit is supposed to, at least up to numerical precision. For example, if you compute avector x that is supposed to satisfy Ax = b (say), show us the matlab code that checksthis, and the result. (This might be done by the matlab code norm(A*x-b); be sureto show us the result, which should be very small.) We will not check your numericalsolutions for you, in cases where there is more than one solution.

1

Page 2: Final Exam Solutions - ee263.stanford.eduee263.stanford.edu/exams/final20/solutions.pdf · discuss the exam with others until August 15, after everyone has taken the exam. The only

• In the portion of your solutions where you explain the mathematical approach, youcannot refer to matlab operators, such as the backslash operator. (You can, of course,refer to inverses of matrices, or any other standard mathematical construct.)

• Some of the problems are described in a practical setting, such as Robotics or Me-chanical systems. You do not need to understand anything about the application areato solve these problems. We’ve taken special care to make sure all the information andmath needed to solve the problem is given in the problem description.

• The zip file for the datasets required for the exam have been emailed to you alongsidethe exam pdf.

• Please respect the honor code. Although we encourage you to work on homeworkassignments in small groups, you cannot discuss the final exam with anyone, with theexception of EE263 course staff, until August 15 when everyone has taken it and thesolutions are posted online.

• Finally, a few hints:

– Problems may be easier (or harder) than they might at first appear.

– None of the problems require long calculations or any serious programming.

2

Page 3: Final Exam Solutions - ee263.stanford.eduee263.stanford.edu/exams/final20/solutions.pdf · discuss the exam with others until August 15, after everyone has taken the exam. The only

1. And away we go... [10 marks]

(a) (3 marks) AAT and ATA have the same eigenvalues except possible zeros? Proveor give a counter example.

(b) (3 marks) If A ∈ Rn×m is full rank and m > n does (AAT )−1 exist? Prove or givea counter example.

(c) (4 marks) Let a, b ∈ Rn and H ∈ S+ where S+ is the set of positive semidefinitematrices, that is xTHx ≥ 0 ∀x ∈ Rn. Show that if Ha = b and Hb = a thena = b. Hint : use a norm

Solution.

(a) True. Let the full-SVD of A be A = UΣV T . Then, AAT = UΣΣTUT andATA = V ΣTΣV T . Therefore, the eigenvalues of AAT are the diagonal entriesof ΣΣT and the eigenvalues of ATA are the diagonal entries of ΣTΣ. Therefore,except possible zeros, the eigenvalues of AAT and ATA are the same.

(b) There are many ways to show this fact, the approach here is to show that AAT

is full rank, which implies invertability because it’s square.

Showing that AAT is full rank is equivalent to showing that it is onto, i.e ∀ythere is b such that AAT b = y. Now lets AT b = x.

Since A is full rank and wide it is onto. Therefore for all y there always existsx such that for Ax = y, Moreover there will exist an x ∈ R(AT ) because for anyother x where Ax = y there is some z ∈ Null(A) such that x + z = x sinceNull(A) and R(AT ) are orthogonal, we can always find an x ∈ R(AT ).

Now since x ∈ R(AT ), but definition there is some b such that x = AT b. Weare done! We have shown the square matrix AAT is onto and therefore full rankand therefore inevitable.

(c) Since a−b ∈ Rn it follows from H being positive semidefinite (a−b)TH(a−b) ≥ 0,but (a− b)TH(a− b) = (a− b)T (Ha−Hb) = (a− b)T (b−a) = −(a− b)T (a− b) =−||a− b|| which must be nonpositive as norms are nonnegative. Therefore

0 ≤ (a− b)TH(a− b) ≤ 0

thus a-b=0 since any other value would violate one of the two statements above.

Some people noticed that H(a-b)=b-a = -(a-b) which implies that a-b is an eigen-vector of H with eigenvalue -1, which would violate the premise, thus either a-b=0.Some claimed that this means H = −I which is indeed not true.

Also some claimed that since ||a|| = ||b|| or aTHa = bTHb then a = b, but that isalso not true, as you can take H = I and a, b as any unit vector

3

Page 4: Final Exam Solutions - ee263.stanford.eduee263.stanford.edu/exams/final20/solutions.pdf · discuss the exam with others until August 15, after everyone has taken the exam. The only

2. They grow up so fast [30 marks].Space. The final frontier. Where there is no food in the cold vacuum.

You are the chief mad scientist on a new space colony charged with growing a newtype of food. We have n dishes where we can grow the food (in this case a colony ofcells). We observe all the dishes for K days. Let x(k) ∈ Rn+1 for k = 1, . . . , K bethe vector of cell populations at the start of the day where the first n elements arethe populations of each dish and the last element of x represents a cellular reservoirof frozen cells. Although populations are normally positive values, for this problemwe will let each element of x be either positive or negative, meaning that a negativepopulation is okay. On day 1 we start with initial non-zero populations in each dishand the reservoir given by x(1) ∈ Rn+1. Each day we have two events that affect ourcolony.

First, cells grow by a certain percent. Let αi ∈ R+ be the daily growth rate associ-ated with dish i. Simply put, at the end of day k the colony population in dish i isαixi(k). Since the cells in the reservoir are frozen they do not grow thus the end-of-daypopulation of xn+1(k) is unchanged by the growth step.

Next, we transfer (thaw or freeze) the cells from or to the reservoir. We do not wishto move cells directly from one dish to another as that might contaminate the growthmaterial in each dish. Suppose ui ∈ R is the amount of cells from dish i we thawfrom (or freeze and move to) the reservoir, note that we must remove or addthat amount from the reservoir, depending on if ui is positive (thaw) or negative(freeze). If we wanted to move cells between dishes, it would take 2 days because theywould have to be frozen first (i.e moved to the reservoir).

(a) (3 marks) Formulate the growth and transfer steps as a linear dynamical system

x(k + 1) = Ax(k) +Bu(k),

where the vector u(k) should have dimension n.

(b) (4 marks) Transferring cells to and from the reservoir can damage them, causinga loss in cell fitness. Since each of the dishes are different growth materials, they”shock” the cells different amounts. Let

ρiui(k)2

model the lost cellular fitness incurred due to transferring ui cells to or from dish iat day k, the cells receive the same damage regardless of being added or removed.The number cells in each dish also contributes to the overall cellular fitness of thecolony as the total number of cells times a constant, the health is

γ1Tx.

Thus the overall fitness of the colony at start of the day K is the health minusthe total damage.

4

Page 5: Final Exam Solutions - ee263.stanford.eduee263.stanford.edu/exams/final20/solutions.pdf · discuss the exam with others until August 15, after everyone has taken the exam. The only

J(K) = γ1Tx(K)−K−1∑k=1

N∑i=1

ρiui(k)2

Represent the overall fitness of the colony at start of the day K, J(K) as a functionof cell populations at day 1 x(1) and the sequence of transfers U ∈ Rn∗(K−1)×1

given by

U =

u(1)...

u(K − 1)

(c) (5 marks) Derive the closed form solution for the optimal sequence of transfers

U∗ such that the cellular fitness at the start of day K, J(K) is maximized.

(d) (8 marks) Apply your method to data below

n=5

gamma=2

alpha= [1.02, 1.03, 1.04, 1.05, 1.01]

K=21

rho=[.2, .3, .4, .5, .7]

x1=[10, 15, 20, 5, 10, 0]

Report the optimal fitness value and a plot overtime of the cell population in eachdish as well as the reservoir. What do you observe?

(e) (10 marks) Now consider another situation. Having cells in the dishes at thestart of day K is useless as we plan to ship the cells to our planetary base, thuswe require x1(K), ..., xn(K) = 0. Formulate another optimization problem thatagain maximizes cell fitness subject to this new requirement. Again, report thenew optimal fitness value and a plot overtime of the cell population in each dish aswell as the reservoir. (Note that now this has becomes a constraint optimizationproblem.)

Solution.

(a) A is an n × n diagonal matrix with where the diagonal is alpha in the first nelements and then the last diagonal element is just 1.

A = diag([α 1]).

B =

1 0 · · · 00 1 0...

. . ....

0 1−1 −1 · · · −1

.

5

Page 6: Final Exam Solutions - ee263.stanford.eduee263.stanford.edu/exams/final20/solutions.pdf · discuss the exam with others until August 15, after everyone has taken the exam. The only

We thus have that

x(k + 1) = Ax(k) +Bu(k), k = 1, . . . , K − 1.

(b) The final state is given by

x(K) = AK−1x(1) +K−1∑k=1

AK−k−1Bu(k)

or equivalentlyx(K) = AK−1x(1) + CU

with

C =[AK−2B AK−3B · · · B

], U =

u(1)u(2)

...u(K − 1)

.Thus the final cost is given by

J = γ ∗ 1T (AK−1x(1) + CU)− UTPU

(c) We can optimize the above cost by taking it gradient with respect to U and settingit to 0.

dJ

dU= γ ∗ CT1− 2PU = 0

thus the optimal solution is

U∗ =γ

2P−1CT1

where P = diag(repmat(ρ, 1, K − 1))

i.e.P = diag(ρ1, ρ2, ρ3..ρn)

P = diag(P , P , P ..., P )

with K − 1 number of P

the code in matlab is

rhoLong=repmat(rho, 1, K-1)

P=diag(rhoLong)

6

Page 7: Final Exam Solutions - ee263.stanford.eduee263.stanford.edu/exams/final20/solutions.pdf · discuss the exam with others until August 15, after everyone has taken the exam. The only

(d) the final cost is 283.9

Figure 1: Growth Unbound

(e) here we have an extra constraint

D(xK) = D(AK−1x(1) +K−1∑k=1

AK−k−1Buk) = D(AK−1x(1) + CU) = 0

7

Page 8: Final Exam Solutions - ee263.stanford.eduee263.stanford.edu/exams/final20/solutions.pdf · discuss the exam with others until August 15, after everyone has taken the exam. The only

where

D =

1 0 0 0 0 00 1 0 0 0 00 0 1 0 0 00 0 0 1 0 00 0 0 0 1 0

thus the Lagrangian to this problem is

L(U , λ) = γ ∗ 1T (AK−1x(1) + CU)− UTPU + λTD(AK−1x(1) + CU)

thus we take the derivatives and the first order equation

L(U , λ)

dU= γ ∗ CT1− 2PU + (DC)Tλ = 0

L(U , λ)

dλ= D(AK−1x(1) + CU) = 0

set up a matrix system

[2P −DCTDC 0

] [Uλ

]=

[γ ∗ CT1

−DAK−1x(1)

]and solve this system[

]=

[2P −DCTDC 0

]−1 [γ ∗ CT1

−DAK−1x(1)

]the cost is 135.2

8

Page 9: Final Exam Solutions - ee263.stanford.eduee263.stanford.edu/exams/final20/solutions.pdf · discuss the exam with others until August 15, after everyone has taken the exam. The only

Figure 2: Ready for Launch!

The codes for parts c and d are:

clear all ; close all ; clc

%%loading the data

n=5;

gamma=2;

alpha= [1.02, 1.03, 1.04, 1.05, 1.01];

K=21;

rho=[.2, .3, .4, .5, .7];

x1=[10, 15, 20, 5, 10, 0];

9

Page 10: Final Exam Solutions - ee263.stanford.eduee263.stanford.edu/exams/final20/solutions.pdf · discuss the exam with others until August 15, after everyone has taken the exam. The only

%%Part C

A=diag([alpha, 1.0]);

B=eye(n);

B=[B; -1*ones(n,1)’];

C= B;

for k=1:K-2

C=[A^k*B C];

end

C;

% cost matrix

rhoLong=repmat(rho, 1,K-1);

P=diag(rhoLong);

% optimal soln

u_opt=gamma/2*inv(P)*C’*ones(6,1);

% simulate

U=reshape(u_opt, n, K-1);

X=zeros(n+1, K);

X(:,1)= x1;

for k=1:K-1

X(:,k+1)= A*X(:,k)+ B*U(:,k);

end

% cost

J= gamma*sum(X(:, end))- u_opt’*P*u_opt;

J

gcol=[’g’, ’r’, ’b’, ’m’, ’c’];

kdays=[1:K];

figure(1)

plot(kdays, X(6, :), ’MarkerEdgeColor’, ’k’)

hold on;

for i=1:n

plot(kdays, X(i, :), ’MarkerEdgeColor’, gcol(i))

end

title("food");

xlabel("days"); ylabel("price");

legend(’reservoir’,’dish 1’,’dish 2’,’dish 3’,’dish 4’,’dish 5’);

saveas(gcf,’1c.png’)

% PART D

D = [eye(5), zeros(5,1)];

DC=D*C;

10

Page 11: Final Exam Solutions - ee263.stanford.eduee263.stanford.edu/exams/final20/solutions.pdf · discuss the exam with others until August 15, after everyone has taken the exam. The only

L=[2*P, -DC’; DC, zeros(n,5)];

drift=A^(K-1)*x1’;

g=[C’*ones(6,1)*gamma; -D*drift];

ul_opt=inv(L)*g;

u1=ul_opt(1:(K-1)*n);

U=reshape(u1, n, K-1);

X=zeros(n+1, K);

X(:,1)= x1;

for k=1:K-1

X(:,k+1)= A*X(:,k)+ B*U(:,k);

end

J= gamma*sum(X(:, end))- u1’*P*u1;

J

gcol=[’g’, ’r’, ’b’, ’m’, ’c’];

kdays=[1:K];

figure(2)

plot(kdays, X(6, :), ’MarkerEdgeColor’, ’k’)

hold on;

for i=1:n

plot(kdays, X(i, :), ’MarkerEdgeColor’, gcol(i))

end

title("Food ready to ship");

xlabel("days"); ylabel("price");

legend(’reservoir’,’dish 1’,’dish 2’,’dish 3’,’dish 4’,’dish 5’);

saveas(gcf,’1d.png’)

11

Page 12: Final Exam Solutions - ee263.stanford.eduee263.stanford.edu/exams/final20/solutions.pdf · discuss the exam with others until August 15, after everyone has taken the exam. The only

3. Attack position of Fighter Jets [30 marks].Consider you are commanding a fleet of MiG-17 fighter jets , labeled 1, . . . , n, whichmove along a line with (scalar) positions y1, . . . , yn. We let v1, . . . , vn denote the veloc-ities of the jets, and u1, . . . , un the net forces applied to the jets. The motions of thesefighter jets are governed by the equations

yi = vi, vi = ui − vi.

(Here we take mass of each jet to be one, and include a damping term in the equations.)We assume that y1(0) < · · · < yn(0), i.e., the jets start out with jet 1 in the leftmostposition, followed by the jet 2 to its right, and so on, with jet n in the rightmostposition. Your fleet has been called to action to bomb an enemy base. In order toachieve this, you must arrange your vehicles in the following attack configuration aftera sufficiently large time:

limt→∞

yi(t) = i, limt→∞

vi(t) = 0, i = 1, . . . , n,

i.e., first jet at position 1, with unit spacing between adjacent jets, and all stationary.We call this configuration aligned, and the goal is to drive the jets to this configuration,i.e., to align the jets. We define the spacing between jet i and i+ 1 as si(t) = yi+1(t)−yi(t), for i = 1, . . . , n−1. (When the jets are aligned, these spacings are all one.) Backat the command center ,You have at your disposal the following three control schemesto achieve the given fleet configuration.

• Right looking control is based on the spacing to the jet to the right. We use thecontrol law

ui(t) = si(t)− 1, i = 1, . . . , n− 1,

for jets i = 1, . . . , n− 1. In other words, we apply a force on jet i proportional toits spacing error with respect to the jet to the right (i.e., jet i+1). The rightmostjet uses the control law

un(t) = −(yn(t)− n),

which applies a force proportional to its position error, in the opposite direction.This control law has the advantage that only the rightmost jet needs an absolutemeasurement sensor; the others only need a measurement of the distance to theirrighthand neighbor.

• Left and right looking control adjusts the input force based on the spacing errorsto the jet to the left and the jet to the right:

ui(t) =si(t)− 1

2− si−1(t)− 1

2, i = 2, . . . , n− 1,

The rightmost jet uses the same absolute method as in right looking control, i.e.,

un(t) = −(yn(t)− n),

12

Page 13: Final Exam Solutions - ee263.stanford.eduee263.stanford.edu/exams/final20/solutions.pdf · discuss the exam with others until August 15, after everyone has taken the exam. The only

and the first jet, which has no jet to its left, uses a right looking control scheme,

u1(t) = s1(t)− 1.

This scheme requires jet n to have an absolute position sensor, but the other jetsonly need to measure the distance to their neighbors.

• Independent alignment is based on each jet independently adjusting its positionwith respect to its required position:

ui(t) = −(yi(t)− i), i = 1, . . . , n.

This scheme requires all jets to have absolute position sensors.

In the questions below, we consider the case where you have n = 7 jets in your squadron.

(a) (4*3+3 marks) Which of the three schemes work? By ‘work’ we mean that thejets converge to the alignment configuration, no matter what the initial positionsand velocities are. Among the schemes that do work, which one gives the fastestasymptotic convergence to alignment? (If there is a tie between two or threeschemes, say so.) In this part of the problem you can ignore the issue of collisionsof the jets, i.e., spacings that pass through zero.Hint: Try expressing each of the control schemes as a Linear Dynamical System.

(b) (5*3 marks) Collisions. In this problem we analyze jet collisions, which occurwhen any spacing between jets is equal to zero. (For example, s3(5.7) = 0 meansthat jets 3 and 4 collide at t = 5.7.) We take the particular starting configuration

y = (0, 1, 2, 4, 6, 7, 8), v = (0, 0, 0, 0, 0, 0, 0),

which corresponds to the jets with zero initial velocity, but not in the alignedpositions. For each of the three schemes above (whether or not they work),determine if a collision occurs. If a collision does occur, find the earliest collision,giving the time and the jets involved in that collision. (For example, ‘jets 3 and4 collide at t = 7.7.’) If there is a tie, i.e., two pairs of jets collide at the sametime, say so. If the jets do not collide, find the point of closest approach, i.e., theminimum spacing that occurs, between any pair of jets, for t ≥ 0. (Give the time,the jets involved, and the minimum spacing.) If there is a tie, i.e., two or morepairs of jets have the same distance of closest approach, say so. Be sure to give ustimes of collisions or closest approach with an absolute precision of at least 0.1.

Solution. We first describe the dynamics of the fleet of jets in terms of the positionerrors, defined as ei(t) = yi(t)− i, i = 1, . . . , n, which are the quantities we care about.We’ll also need the position error velocities, ei(t), for i = 1, . . . , n. From

ei(t) = yi(t) = vi(t), i = 1, . . . , n,

13

Page 14: Final Exam Solutions - ee263.stanford.eduee263.stanford.edu/exams/final20/solutions.pdf · discuss the exam with others until August 15, after everyone has taken the exam. The only

and using the dynamics of the jets we obtain

ei(t) = vi(t) = ui(t)− vi(t)= −ei(t) + ui(t), i = 1, . . . , n.

We can write these differential equations as a linear dynamical system x = Ax + Bu,where the state is x = (e1, . . . , en, e1, . . . , en) and the input is u = (u1, u2, . . . , un). Ifwe can express the input u as a linear function of the state x, then the whole systembecomes an autonomous LDS. Our claim is that with the given state x, all of the controlschemes can be represented in such a way. Now we consider each control scheme. Theright looking control is given by ui(t) = si(t) − 1 = yi+1 − yi − 1 for i = 1, . . . , n − 1,and for the rightmost jet by un(t) = −(yn(t)− n) = −en(t), which is just the negativeof its position error. Using yi(t) = ei(t) + i, we express the control law as

ui(t) = yi+1 − yi − 1

= (ei+1 + i+ 1)− (ei + i)− 1

= ei+1 − ei, i = 1, . . . , n− 1.

Therefore, the e(t) can be written as

ei(t) = −ei(t)− ei(t) + ei+1(t), i = 1, . . . , n− 1,

anden(t) = −en(t)− en(t).

We express these differential equations as an autonomous LDS

x =

[0 IF rl −I

]x = Arlx,

where

F rl =

−1 1 0 · · · 00 −1 1 · · · 0...

. . . . . ....

0 · · · 0 −1 10 · · · 0 0 −1

.The left and right looking control for jets i = 2, . . . , n− 1 is given by

ui(t) =si(t)− 1

2− si−1(t)− 1

2

=yi+1(t)− yi(t)− 1

2− yi(t)− yi−1(t)− 1

2

=(ei+1(t) + i+ 1)− (ei + i)− (ei + i) + (ei−1(t) + i− 1)

2

= ei+1(t)/2− ei(t) + ei−1(t)/2, for i = 2, . . . , n− 1.

14

Page 15: Final Exam Solutions - ee263.stanford.eduee263.stanford.edu/exams/final20/solutions.pdf · discuss the exam with others until August 15, after everyone has taken the exam. The only

For the rightmost jet we have un(t) = −en(t), and for the leftmost jet we have theright looking control law u1(t) = s1(t)− 1. Therefore, we have differential equations

e1(t) = −e1(t)− e1(t) + e2(t),

ei(t) = −ei(t) + ei−1(t)/2− ei(t) + ei+1(t)/2, i = 2, . . . , n− 1,

en(t) = −en(t)− en(t).

In this case, we can express the system as an autonomous LDS

x =

[0 IF lrl −I

]x = Alrlx,

where

F lrl =

−1 1 0 0 · · · 01/2 −1 1/2 0 · · · 00 1/2 −1 1/2 0...

. . . . . ....

0 1/2 −1 1/2 00 · · · 0 1/2 −1 1/20 · · · 0 0 0 −1

The independent alignment control scheme has form

ui(t) = −(yi(t)− i) = −ei(t), i = 1, . . . , n,

and we haveei(t) = −ei(t)− ei(t), i = 1, . . . , n.

The state equations are now

x =

[0 I−I −I

]x = Aiax.

We are ready to answer the questions.

(a) A given control scheme ‘works’ provided the state x (which contains the positionerrors ei and their derivatives) always converges to zero. This is the same asstability of the corresponding linear dynamical system. We can check this byfinding the eigenvalues of Arl, Alrl, and Aia, and checking if all eigenvalues havenegative real part. The matlab code below verifies that all three control schemesare stable.

% alignment of a fleet of vehicles

n = 7; % number of vehicles = number of states

% scheme 1: right looking control

15

Page 16: Final Exam Solutions - ee263.stanford.eduee263.stanford.edu/exams/final20/solutions.pdf · discuss the exam with others until August 15, after everyone has taken the exam. The only

Frl = diag(-ones(n,1)) + diag(ones(n-1,1),1);

Arl = [zeros(n,n) eye(n,n); Frl -eye(n,n)];

% scheme 2: left and right looking control

Flrl = diag(-ones(n,1)) + diag([1/2*ones(n-2,1); 0],-1) ...

+ diag([1; 1/2*ones(n-2,1)],1);

Alrl = [zeros(n,n) eye(n,n); Flrl -eye(n,n)];

% scheme 3: independent alignment

Aia = [zeros(n,n) eye(n,n); -eye(n,n) -eye(n,n)];

% stability

>> max(real(eig(Arl)))

-0.4999

>> max(real(eig(Alrl)))

-0.0353

>> max(real(eig(Aia)))

-0.5000

The asymptotic convergence rate to alignment is determined by r = max<λi, i.e.,the convergence to alignment will be dominated by the eigenvalue with the largestreal part. For a faster convergence, we want r to be as small as possible. For eachof the control schemes, we have rrl = −0.4999, rlrl = −0.0353, and ria = −0.5000.Therefore, the ‘right looking’ and ‘independent alignment’ schemes are almosttied for the fastest asymptotic convergence to alignment.

(b) In order to determine if there are collisions between jets, we need to analyzethe spacing between jets for each of the control schemes. If the spacing si(t) =yi+1(t)−yi(t) is equal to zero, we have a collision between jets i and i+1. We havealready expressed the dynamics of the jet fleet as an autonomous linear dynamicalsystem with state x = (e1, . . . , en, e1, . . . , en). Let’s see if we can obtain jet spacingfrom these state variables x.

si(t) = yi+1(t)− yi(t) = (ei+1(t) + i+ 1)− (ei(t) + i) = ei+1(t)− ei(t) + 1,

for i = 1, . . . , n− 1. Using matrix notation and for n = 7, we have

s(t) =

−1 1 0 0 0 0 00 −1 1 0 0 0 00 0 −1 1 0 0 00 0 0 −1 1 0 00 0 0 0 −1 1 00 0 0 0 0 −1 1

06×7

x(t) + 1 = Cx(t) + 1.

Now we can solve this problem by simulating each control scheme and looking for

16

Page 17: Final Exam Solutions - ee263.stanford.eduee263.stanford.edu/exams/final20/solutions.pdf · discuss the exam with others until August 15, after everyone has taken the exam. The only

zero crossings of its jet spacing values. This is given by

s(t) = Cx(t) + 1 = CeAtx(0) + 1,

where

x(0) =

e1(0)...

e7(0)e1(0)

...e7(0)

=

y1(0)− 1...

y7(0)− 7v1(0)

...v7(0)

.

Using the initial values y(0) = (0, 1, 2, 4, 6, 7, 8) and v(0) = (0, 0, 0, 0, 0, 0, 0), wesimulate each control system and plot the associated spacings. The plot of ‘rightlooking’ control spacings is shown below.

17

Page 18: Final Exam Solutions - ee263.stanford.eduee263.stanford.edu/exams/final20/solutions.pdf · discuss the exam with others until August 15, after everyone has taken the exam. The only

0 5 10 15 20 25-2

0

2s1

vehicle spacing

0 5 10 15 20 250

1

2

s2

0 5 10 15 20 250

1

2

s3

0 5 10 15 20 250

1

2

s4

0 5 10 15 20 250

1

2

s5

0 5 10 15 20 25

t

0

1

2

s6

From the plot we can see that the first collision occurs at t = 8.35, between jets1 and 2. The plot of ‘right and left looking’ control spacings is shown below.

18

Page 19: Final Exam Solutions - ee263.stanford.eduee263.stanford.edu/exams/final20/solutions.pdf · discuss the exam with others until August 15, after everyone has taken the exam. The only

0 5 10 15 20 251

1.1

1.2s1

vehicle spacing

0 5 10 15 20 251

1.5

s2

0 5 10 15 20 251

1.5

2

s3

0 5 10 15 20 251

1.5

2

s4

0 5 10 15 20 250.5

1

1.5

s5

0 5 10 15 20 25

t

0

1

2

s6

This plot shows that no collision occurs. The point of closest approach is foundby finding the time and component of s at which it attains its smallest valuefor t ≥ 0. This is between jets 6 and 7, at t = 2.33, and the distance of closestapproach is 0.3146. The plot of ‘independent alignment’ control spacings is shownbelow.

19

Page 20: Final Exam Solutions - ee263.stanford.eduee263.stanford.edu/exams/final20/solutions.pdf · discuss the exam with others until August 15, after everyone has taken the exam. The only

0 5 10 15 20 250

1

2

s1

vehicle spacing

0 5 10 15 20 250.9999999999998

1

1.0000000000002

s2

0 5 10 15 20 250

1

2

s3

0 5 10 15 20 250

1

2

s4

0 5 10 15 20 250.9999999999998

1

1.0000000000002

s5

0 5 10 15 20 25

t

0

1

2

s6

Two spacings achieve the minimum value, 0.837, at t = 3.63. These are: jets 3and 4, and jets 4 and 5. Matlab code used for simulation of all the control schemesis provided below. Running the above matlab code produces

>> right looking simulation

t =

8.3500

20

Page 21: Final Exam Solutions - ee263.stanford.eduee263.stanford.edu/exams/final20/solutions.pdf · discuss the exam with others until August 15, after everyone has taken the exam. The only

crash_occurred =

1

collision between 1 and 2

>> left and right looking simulation

S_close =

1.0000

1.0000

1.0327

1.0426

0.8909

0.3146

t_close =

0

0

25.0000

25.0000

4.8000

2.3300

>> independent alignment simulation

S_close =

1.0000

1.0000

0.8370

0.8370

1.0000

1.0000

t_close =

21

Page 22: Final Exam Solutions - ee263.stanford.eduee263.stanford.edu/exams/final20/solutions.pdf · discuss the exam with others until August 15, after everyone has taken the exam. The only

0

4.0600

3.6300

3.6300

1.6700

0

To summarize, the ‘right looking’ control is the only scheme for which we havea collision. For the other two schemes, we find the points and times of closestapproach between jets.

22

Page 23: Final Exam Solutions - ee263.stanford.eduee263.stanford.edu/exams/final20/solutions.pdf · discuss the exam with others until August 15, after everyone has taken the exam. The only

4. UN General Assembly voting [30 marks].CNN News network has decided to analyse the voting patterns of countries in the UNGeneral Assembly which comprises of both capitalist and communist nations along withsocialist nations which essentially follow a stance between the two hard-core ideologies.As the journalist assigned to this study, you collect the results of votes on the keyeconomic issues raised in the Assembly for the year 2018-19. This data is then compiledby your team into the file un voting patterns.m, which defines the following variables.

• countries, a 102 × 2 cell array. There are 102 rows because Tanzania exitedduring its term, and was replaced by Belgium. Also Albania, has been switchingits stance through the year, recording both pro-capitalism and socialists votes

– countries{i,1} is the name of the ith country

– countries{i,2} is the economy type of the ith country

• votes, a 102×633 matrix where votes(i,j) is the vote cast by country i in votej (+1 if country i voted “Yea” on vote j, −1 if country i voted “Nay” on vote j,and 0 if country i did not participate in vote j)

(a) (5 marks) Make a stem plot of the singular values of votes. How many signifi-cant singular values are there? The fraction of the variation in the voting dataassociated with the first two singular values is

f2 =σ21 + σ2

2∑ri=1 σ

2i

.

What is f2 for the Assembly voting data?

(b) (9 marks) Missing votes will complicate our subsequent analysis, so we use a low-rank model of the voting matrix to guess the missing votes. Initialize A to theobserved voting matrix; repeat the following steps until convergence:

• replace A with its best rank-two approximation;

• replace the entries of A corresponding to the known votes with their truevalues;

• replace the entries of A corresponding to the unknown votes by setting non-negative entries to +1, and negative entries to −1.

Report the numbers of +1’s and −1’s in your final matrix A.

(c) (3*2+2 marks) Let A = UΣV T be the singular-value decomposition of A. Wewant to find interpretations for the first two left singular vectors, u1 and u2.

i. The function spatial_plot, which is available in the data zip file, can beused to generate color-coded scatter plots. Use this function to make a scat-ter plot of (u1)i and (u2)i where Capitalists, Communists and Socialists arerepresented by red, blue, and green markers, respectively. You can make sucha plot using the command

23

Page 24: Final Exam Solutions - ee263.stanford.eduee263.stanford.edu/exams/final20/solutions.pdf · discuss the exam with others until August 15, after everyone has taken the exam. The only

spatial_plot(u1 , u2 , z , 3 , eye(3));

where u1 and u2 are the first two left singular vectors of A, and z is a vectorwhere z(i) is 0 if country i is a Capitalist economy, 1 if country i is a Socialisteconomy, and 2 if country i is a Communist economy.

ii. Make a scatter plot showing the fraction of votes in which each country votedwith the majority of the other countries. You can make such a plot using thecommand

spatial_plot(u1 , u2 , z , 10);

where u1 and u2 are the first two left singular vectors of A, and z is a vectorwhere z(i) is the fraction of votes j for which

Aij = sgn(102∑ı=1

Aıj).

(By default, spatial_plot uses the cool color map, which is pink for largevalues, and blue for small values. Also, sgn refers to the sign function.)

Based on these plots, give intuitive interpretations of (u1)i and (u2)i.

(d) (3*2+2 marks) We can also find interpretations for the first two right singularvectors.

i. Make a scatter plot of (v1)j and (v2)j where the colors indicate the totalsupport received by vote j. In particular, the color should correspond to

zj =102∑i=1

Aij.

ii. Make a scatter plot of (v1)j and (v2)j where the colors indicate the partisansupport received by vote j. In particular, let Cap ⊂ {1, . . . , 102} be the setof Capitalists, and let Com ⊂ {1, . . . , 102} be the set of Communists. Thecolor in your plot should correspond to

zj =1

|Cap|∑i∈Cap

Aij −1

|Com|∑

i∈Com

Aij.

Based on these plots, give intuitive interpretations of (v1)j and (v2)j.

The data given in the above question is artificially generated and should not be takenas an indicator for the world reality in any way whatsoever.

Solution.

24

Page 25: Final Exam Solutions - ee263.stanford.eduee263.stanford.edu/exams/final20/solutions.pdf · discuss the exam with others until August 15, after everyone has taken the exam. The only

(a) A stem plot of the singular values of votes is given in Fig: ??. There appearto be two especially significant singular values. In particular, the fraction ofthe variation in the voting data associated with the first two singular values isf2 = 0.7307: that is, the first two singular values account for over 73% of thevariation in the voting data.

(b) The number of +1s in the final A is 44934, while the number of −1s is 19632.

(c) i. The scatter plot of ideology affiliation is given in Fig: ??.

ii. The scatter plot of rate of agreement with the majority vote is given in Fig:??.

Based on these plots, it seems like (u1)i measures how often country i agrees withthe majority vote; all the values of (u1)i are negative, and more negative valuescorrespond to a higher rate of agreeing with the majority vote. It seems like (u2)imeasures country i’s ideology affiliation: it is generally positive for Capitalists,and negative for Communists.

(d) i. The scatter plot of total support is given in Fig: ??.

ii. The scatter plot of partisan support is given in Fig: ??.

Based on these plots, it seems like (v1)j measures the total support for vote j, withnegative values representing widespread support, and positive values representinglimited support. It seems like (v2)j measures the partisan support for vote j, withpositive values representing support from Capitalists, but not Communists, andnegative values representing support from Communists, but not Capitalists.

clear all ; close all ; clc

un_voting_patterns;

% compute the singular-value decomposition of votes

[~,S,~] = svd(votes , ’econ’);

figure();

stem(1:length(S) , diag(S));

xlabel(’i’);

ylabel(’sigma_i’);

f2 = sum([S(1,1) S(2,2)].^2) / sum(diag(S).^2)

% estimate the unobserved votes

A = votes;

for k = 1:1000

[U,S,V] = svds(A,2);

Anext = U*S*V’;

Anext(votes ~= 0) = votes(votes ~= 0);

Anext = 1 - 2 * (Anext < 0);

25

Page 26: Final Exam Solutions - ee263.stanford.eduee263.stanford.edu/exams/final20/solutions.pdf · discuss the exam with others until August 15, after everyone has taken the exam. The only

if norm(A-Anext) < 1e-9

break;

end

A = Anext;

end

[U,S,V] = svds(A,2);

Aplus = sum(A(:) == +1)

Aminus = sum(A(:) == -1)

% plots of left singular vectors

idxR = strcmp(’Cap’ , countries(:,2));

idxD = strcmp(’Com’ , countries(:,2));

country = ones(size(votes,1),1);

country(idxR) = 0;

country(idxD) = 2;

spatial_plot(U(:,1) , U(:,2) , country , 3 , eye(3));

xlabel(’u_{1}’);

ylabel(’u_{2}’);

r = nan(size(U,1),1);

for i = 1:size(U,1)

r(i) = mean(sign(sum(A)) == A(i,:));

end

spatial_plot(U(:,1) , U(:,2) , r , 10);

xlabel(’u_{1}’);

ylabel(’u_{2}’);

% plots of right singular vectors

spatial_plot(V(:,1) , V(:,2) , sum(A) , 10);

xlabel(’v_{1}’);

ylabel(’v_{2}’);

partisan_support = mean(A(idxR,:)) - mean(A(idxD,:));

spatial_plot(V(:,1) , V(:,2) , partisan_support , 10);

xlabel(’v_{1}’);

ylabel(’v_{2}’);

f2. = 0.7307,

Aplus = 44934,

Aminus = 19632

26

Page 27: Final Exam Solutions - ee263.stanford.eduee263.stanford.edu/exams/final20/solutions.pdf · discuss the exam with others until August 15, after everyone has taken the exam. The only

Figure 3: the singular values of the voting matrix

Congratulations! You’ve finished EE263! We hope this was a great learning experience foryou all and we wish you the best in all of your future endeavors.

27

Page 28: Final Exam Solutions - ee263.stanford.eduee263.stanford.edu/exams/final20/solutions.pdf · discuss the exam with others until August 15, after everyone has taken the exam. The only

Figure 4: the first two left singular vectors color-coded by ideology affiliation

28

Page 29: Final Exam Solutions - ee263.stanford.eduee263.stanford.edu/exams/final20/solutions.pdf · discuss the exam with others until August 15, after everyone has taken the exam. The only

Figure 5: the first two left singular vectors color-coded by agreement with majorityvote

29

Page 30: Final Exam Solutions - ee263.stanford.eduee263.stanford.edu/exams/final20/solutions.pdf · discuss the exam with others until August 15, after everyone has taken the exam. The only

Figure 6: the first two right singular vectors color-coded by total support

30

Page 31: Final Exam Solutions - ee263.stanford.eduee263.stanford.edu/exams/final20/solutions.pdf · discuss the exam with others until August 15, after everyone has taken the exam. The only

Figure 7: the first two right singular vectors color-coded by partisan support

31