You are on page 1of 11

EECS 16B Designing Information Devices and Systems II

Fall 2017 Miki Lustig and Michel Maharbiz Homework 8


This homework is due October 31, 2017, at noon.

1. SVD I
Find the singular value decomposition of the following matrix (leave all work in exact form, not decimal):
" #
2 2
A=
3 −3
(a) Find the eigenvalues of AA> and order them from largest to smallest, λ1 > λ2 .

Solution:
λ1 = 18 , λ2 = 8

(b) Find orthonormal eigenvectors ~ui of AA> (all eigenvectors are mutually orthogonal and unit length).

Solution: " # " #


0 1
~u1 = , ~u2 =
1 0


(c) Find the singular values σi = λi . Find the ~vi vectors from:

A>~ui = σi~vi

Solution: √ √
σ1 = 3 2 , σ2 = 2 2
" 1 # " 1 #
√ √
~v1 = 2 , ~v2 = 2
− √12 √1
2

(d) Write out A as a weighted sum of rank-1 matrices:

A = σ1~u1~v> u2~v>
1 + σ2~ 2

Solution: " # " #


√ 0 0 √ √1 √1
A=3 2 √1
+2 2 2 2
2
− √12 0 0

EECS 16B, Fall 2017, Homework 8 1


(e) Use numpy.linalg.svd to compute the SVD of A and compare it to your results for the previous
part. Will calculating the SVD by hand and calculating it using numpy always return identical results
(up to floating point error)? Why or why not?
Note: Be sure to carefully read the documentation for the svd function. In particular, pay attention to
the format of the returned values.

Solution: See ipython notebook

2. SVD II
Find the singular value decomposition of the following matrix (leave all work in exact form, not decimal):
 √ 
1 0 − 3
√
A= 3 0 1 

0 3 0
(a) Find the eigenvalues of A> A and order them from largest to smallest, λ1 > λ2 .

Solution:
λ1 = 9 , λ2 = 4 , λ3 = 4

(b) Find orthonormal eigenvectors ~vi of A> A (all eigenvectors are mutually orthogonal and unit length).

Solution:  
0
~v1 = 1
 
0

Since λ2 = λ3 , any two mutually orthogonal unit vectors that are also orthogonal to ~v1 = [0, 1, 0]> will
work. For example:    
1 0
~v2 = 0 , ~v3 = 0
   
0 1


(c) Find the singular values σi = λi . Find the ~ui vectors from:

A~vi = σi~ui

Solution:
σ1 = 3 , σ2 = 2 , σ3 = 2
     √ 
1
0 √2 − 3
 3  12 
~u1 = 0 , ~u2 =  2  , ~u3 =  2 
 
1 0 0

EECS 16B, Fall 2017, Homework 8 2


(d) Write out A as a weighted sum of rank-1 matrices:

A = σ1~u1~v> u2~v>
1 + σ2~ u3~v>
2 + σ3~ 3

Solution:      √ 
1
0 0 0 0 0 − 3 0 0
 √23  12
A = 3 0 0 0 + 2  2 0 0 + 2  2
   
0 0
0 1 0 0 0 0 0 0 0

3. Balance
Justin is working on a small jumping robot named Salto. Salto can bounce around on the ground, but Justin
would like Salto to balance on its toe and stand still. In this problem, we’ll work on systems that could help
Salto balance on its toe using its reaction wheel tail.

Figure 1: Picture of Salto and the x-z physics model. You can watch a video of Salto here: http://www.
youtube.com/watch?v=2dJmArHRn0U
Standing on the ground, Salto’s dynamics in the x-z plane (called the sagittal plane in biology) look like an
inverted pendulum with a flywheel on the end:

(I1 + (m1 + m2 )l 2 )θ̈1 = −Kt u + (m1 + m2 )lg sin(θ1 )


I2 θ̈2 = Kt u

Where θ1 is the angle of the robot’s body relative to the ground (0 is straight up), θ̇1 is its angular velocity, θ̇2
is the angular velocity of the reaction wheel tail, and u is the current input to the tail motor. m1 , m2 , I1 , I2 , l, Kt
are positive constants representing system parameters (masses and angular momentums of the body and tail,
leg length, and motor torque constant respectively) and g = 9.81m/s2 is the acceleration due to gravity.
Numerically substituting Salto’s physical parameters, the differential equations become approximately:

0.001θ̈1 = −0.025u + 0.1 sin(θ1 )


5(10−5 )θ̈2 = 0.025u

EECS 16B, Fall 2017, Homework 8 3


For this problem, we’ll look at a reduced suite of sensors on Salto. Our only output will be the tail encoder
that measures the angular velocity of the tail relative to the body:
y = θ̇2 − θ̇1

(a) Using the state vector [θ1 , θ̇1 , θ̇2 ]> , input u, and output y linearize the system about the the point
[0, 0, 0]> . Write the linearized equations as dtd ~x = A~x + Bu and y = C~x. Write the matrices with the
physical numerical values, not symbolically.
Note: since the tail is like a wheel, we care only about its angular velocity θ̇2 and not its angle θ2 .

Solution: Numerically, the dynamics are:


      
θ̇1 0 1 0 θ1 0
θ̈1  = 100 0 0 θ̇1  + −25 u
      
θ̈2 0 0 0 θ̇2 500
 
h i θ1
y = 0 −1 1 θ̇1 
 
θ̇2

For those interested, the symbolic dynamics are:


      
θ̇1 0 1 0 θ1 0
   (m1 +m2 )lg sin(θ ) Kt
θ̈1  =  I1 +(m1 +m2 )l 2 0 0 θ̇1  + − I1 +(m1 +m u
   
2
2 )l 
θ̈2 K t
0 0 0 θ̇2 I2
 
h i θ1
y = 0 −1 1 θ̇1 
 
θ̇2

Note: text in red are solutions for if you solved before a typo was fixed
If you solved before the typo fix using:
0.001θ̈1 = −0.025u + 100 sin(θ1 )
Then the dynamics are:
      
θ̇1 0 1 0 θ1 0
   5
θ̈1  = 10 0 0 θ̇1  + −25 u
   
θ̈2 0 0 0 θ̇2 500
 
h i θ1
y = 0 −1 1 θ̇1 
 
θ̇2

(b) Is the system fully controllable? Is the system fully observable?

Solution:  
h i 0 −25 0
C = B AB A2 B = −25 0 −2500
 
500 0 0

EECS 16B, Fall 2017, Homework 8 4


which is full rank so the system is fully controllable.
   
C 0 −1 1
O =  CA  = −100 0 0
   
CA2 0 −100 0

which is rank 3 so the system is fully observable.

If you solved before the typo fix and used:

0.001θ̈1 = −0.025u + 100 sin(θ1 )

Then you get:  


h i 0 −25 0
C = B AB A2 B = −25 0 −25 ∗ 105 
 
500 0 0
   
C 0 −1 1
O =  CA  = −105 0 0
   
CA 2 0 5
−10 0
Both observability and controllability matrices are rank 3, so the system is controllable and observable.

(c) Design an observer of the form dtd x̂ = Ax̂ + Bu − L(Cx̂ − y) and solve for the gains in L that make the
observer dynamics converge with all eigenvalues λ1 = λ2 = λ3 = −10.

Solution: The observer dynamics are dictated by

~e˙ = (A + LC)~e

where~e is the error between the estimated state x̂ and the true state~x. The characteristic polynomial is:

A + LC = 0


0 1 + l1 −l1

100 l2 −l2 = 0

0 l3 −l3

λ 3 + (l3 − l2 )λ 2 + (−100l1 − 100)λ − 100l3 = 0

The desired characteristic polynomial is:

(λ + 10)3 = 0
λ 3 + 30λ 2 + 300λ + 1000 = 0

which we can achieve by matching the coefficients of matching powers:

l3 − l2 = 30
−100l1 − 100 = 300
−100l3 = 1000

EECS 16B, Fall 2017, Homework 8 5


These equations are solved by the gains: l1 = −4, l2 = −40, and l3 = −10. Written as a matrix,
h i
L = −4 −40 −10

If you solved before the typo fix and set λ1 = λ2 = λ3 = 10, then the characteristic polynomial is:
(λ − 10)3 = 0
λ 3 − 30λ 2 + 300λ − 1000 = 0
which we can achieve by matching the coefficients of matching powers:
l3 − l2 = −30
−100l1 − 100 = 300
−100l3 = −1000

Solving the system of equations gives you:


h i
L = −4 40 10

If you solved using:


0.001θ̈1 = −0.025u + 100 sin(θ1 )
And set λ1 = λ2 = λ3 = −10, then the characteristic polynomial for the error is:

0 1 + l1 −l1

5
10 l2 −l2 = 0

0 l3 −l3

λ 3 + (l3 − l2 )λ 2 + (−105 l1 − 105 )λ − 105 l3 = 0


Matching coefficients:
l3 − l2 = 30
−10 l1 − 105 = 300
5

−105 l3 = 1000

Solving the system of equations gives you:


h i
L = −1.003 −30.01 −0.01

If you solved using:


0.001θ̈1 = −0.025u + 100 sin(θ1 )
And set λ1 = λ2 = λ3 = 10, then you get:
h i
L = −1.003 30.01 0.01

EECS 16B, Fall 2017, Homework 8 6


Figure 2: Circuit components and block diagram symbols.
(d) Let’s implement a controller for our system using an analog electrical circuit! You can use the follow-
ing circuit components in Figure 2:
h i
Using state feedback, Justin has selected the control gains K̃ = 20 5 0.01 . Draw a circuit in the
box in Figure 3 that implements this controller. Use relatively reasonable component values.
Optional bonus: what are the eigenvalues of the closed loop dynamics for the given K?

Figure 3: Fill in the box to implement the state feedback controller

Solution:
The original diagram for the summer circuit was incorrect. Circuits which had a resistor value of n ∗ R1
for the feedback of the the first amplifier in the summing block will not be deducted points.

EECS 16B, Fall 2017, Homework 8 7


Figure 4: Here is a possible circuit. Other resistor values will work as long as the gains are the same.

4. Closed-loop control of SIXT33N


Last time, we discovered that open-loop control was not enough to ensure that our car goes straight in the
event of model mismatch. In this problem, we will introduce closed-loop control which will hopefully make
SIXT33N finally go straight.
Previously, we introduced δ (t) = dL (t) − dR (t) as the difference in positions between the two wheels. If
both wheels of the car are going at the same velocity, then this difference δ should remain constant, since
no wheel will advance by more ticks than the other. In our closed loop control scheme, we will consider
a control scheme which will apply a simple proportional control kL and kR against δ (t) in order to try to
prevent |δ (t)| from growing without bound.

vL (t) = dL (t + 1) − dL (t) = θL uL (t) − βL


vR (t) = dR (t + 1) − dR (t) = θR uR (t) − βR

We want to achieve the following equations:

EECS 16B, Fall 2017, Homework 8 8


vL (t) = dL (t + 1) − dL (t) = v∗ − kL δ (t)
vR (t) = dR (t + 1) − dR (t) = v∗ + kR δ (t)

We can put the equations in the following form to figure out how we should change our control inputs.

v∗ + βL δ (t)
vL (t) = dL (t + 1) − dL (t) = θL ( − kL ) − βL
θL θL
v∗ + βR δ (t)
vR (t) = dR (t + 1) − dR (t) = θR ( + kR ) − βR
θR θR

These are our new closed-loop control inputs - the new closed-loop proportional control is the kL /kR term.

v∗ + βL δ (t)
uL (t) = − kL
θL θL

v + βR δ (t)
uR (t) = + kR
θR θR

(a) Let’s examine the feedback proportions kL and kR more closely. Should they be positive or negative?
What do they mean? Think about how they interact with δ (t).

Solution: If δ (t) > 0, it means that dL (t) > dR (t), so the left wheel is ahead of the right one. In order
to correct for this, we should help the right wheel catch up, and we should do this by making kL > 0 in
order to apply less power on the left wheel and kR > 0 in order to apply more power to the right wheel.
Likewise, if δ (t) < 0, it means that dL (t) < dR (t), so the right wheel is ahead of the left one. In this
case, kL > 0 is still valid, since kL δ (t) > 0 and so the left wheel speeds up, and likewise kR > 0 is still
correct since kR δ (t) < 0 so the right wheel slows down.
(b) Let’s look a bit more closely at picking kL and kR . Firstly, we need to figure out what happens to δ (t)
over time. Find δ (t + 1) in terms of δ (t).

Solution:

δ (t + 1) = dL (t + 1) − dR (t + 1)
= v∗ − kL δ (t) + dL (t) − (v∗ + kR δ (t) + dR (t))
= v∗ − kL δ (t) + dL (t) − v∗ − kR δ (t) − dR (t)
= −kL δ (t) − kR δ (t) + (dL (t) − dR (t))
= −kL δ (t) − kR δ (t) + δ (t)
= δ (t)(1 − kL − kR )

EECS 16B, Fall 2017, Homework 8 9


(c) Given your work above, what is the eigenvalue of the system defined by δ (t)? For discrete-time
systems like our system, λ ∈ [−1, 1] is considered stable. Are λ ∈ [0, 1] and λ ∈ [−1, 0] identical in
function for our system? Which one is "better"? (Hint: preventing oscillation is a desired benefit.)
Based on your choice for the range of λ above, how should we set kL and kR in the end?

Solution: The eigenvalue is λ = 1 − kL − kR .


As a discrete system, both are stable, but λ ∈ [−1, 0] will cause the car to oscillate due to overly high
gain. Therefore, we should choose λ ∈ [0, 1].
As a result, 1 − kL − kR ∈ [0, 1] → (kL + kR ) ∈ [0, 1] means that we should set the gains such that
(kL + kR ) ∈ [0, 1].
(d) Let’s re-introduce the model mismatch from last week in order to model environmental discrepancies,
disturbances, etc. How does closed-loop control fare under model mismatch? Find δss = δ (t → ∞),
assuming that δ (0) = δ0 . What is δss ? (To make this easier, you may leave your answer in terms of
appropriately defined c and λ obtained from an equation in the form of δ (t + 1) = δ (t)λ + c.)
Check your work by verifying that you reproduce the equation in part (c) if all model mismatch terms
are zero. Is it better than the open-loop model mismatch case from last week?

vL (t) = dL (t + 1) − dL (t) = (θL + ∆θL )uL (t) − (βL + ∆βL )


vR (t) = dR (t + 1) − dR (t) = (θR + ∆θR )uR (t) − (βR + ∆βR )

v∗ + βL δ (t)
uL (t) = − kL
θL θL
v∗ + βR δ (t)
uR (t) = + kR
θR θR

Solution:

δ (t + 1) = dL (t + 1) − dR (t + 1)
= (θL + ∆θL )uL (t) − (βL + ∆βL ) + dL (t) − ((θR + ∆θR )uR (t) − (βR + ∆βR ) + dR (t))
= θL uL (t) − βL + ∆θL uL (t) − ∆βL + dL (t) − (θR uR (t) − βR + ∆θR uR (t) − ∆βR + dR (t))
= v∗ − kL δ (t) + ∆θL uL (t) − ∆βL + dL (t) − (v∗ + kR δ (t) + ∆θR uR (t) − ∆βR + dR (t))
= v∗ − kL δ (t) + ∆θL uL (t) − ∆βL + dL (t) − v∗ − kR δ (t) − ∆θR uR (t) + ∆βR − dR (t)
= v∗ − v∗ + (dL (t) − dR (t)) − kL δ (t) − kR δ (t) + ∆θL uL (t) − ∆βL − ∆θR uR (t) + ∆βR
= δ (t)(1 − kL − kR ) + ∆θL uL (t) − ∆βL − ∆θR uR (t) + ∆βR
v∗ + βL δ (t) v∗ + βR δ (t)
= δ (t)(1 − kL − kR ) + ∆θL ( − kL ) − ∆θR ( + kR ) − ∆βL + ∆βR
θL θL θR θR
∆θL ∗ ∆θL ∆θR ∗ ∆θR
= δ (t)(1 − kL − kR ) + (v + βL ) − δ (t)kL − (v + βR ) − δ (t)kR − ∆βL + ∆βR
θL θL θR θR
∆θL ∆θR ∆θL ∗ ∆θR ∗
= δ (t)(1 − kL − kR − kL − kR )+ (v + βL ) − (v + βR ) − ∆βL + ∆βR
θL θR θL θR
∆θL ∆θR ∆θL ∗ ∆θR ∗
= δ (t)(1 − kL − kR − kL − kR )+( (v + βL ) − ∆βL ) − ( (v + βR ) − ∆βR )
θL θR θL θR

EECS 16B, Fall 2017, Homework 8 10


∆θL ∗ ∆θR ∗
Let us define c = ( (v + βL ) − ∆βL ) − ( (v + βR ) − ∆βR ), and our new eigenvalue λ = 1 −
θL θR
∆θL ∆θR
kL − kR − kL − kR . In this case,
θL θR

δ (1) = δ0 λ + c
δ (2) = λ (δ0 λ + c) + c = δ0 λ 2 + cλ + c
δ (3) = λ (δ0 λ 2 + cλ + c) + c = δ0 λ 3 + cλ 2 + cλ + c
δ (4) = λ (δ0 λ 3 + cλ 2 + cλ + c) + c = δ0 λ 4 + cλ 3 + cλ 2 + cλ + c
δ (5) = δ0 λ 5 + c(λ 4 + λ 3 + λ 2 + λ 1 + 1)
δ (n) = δ0 λ n + c(1 + λ 1 + λ 2 + λ 3 + λ 4 + ... + λ n )
n
δ (n) = δ0 λ n + c( ∑ λ k ) (rewriting in sum notation)
k=0
1−λn
δ (n) = δ0 λ n + c( ) (sum of a geometric series)
1−λ

If λ < 1, then λ ∞ = 0, so those terms drop out:

1−λ∞
δ (n = t → ∞) = δ0 λ ∞ + c( )
1−λ
1
δ (n = t → ∞) = c
1−λ

1
δss = c
1−λ
For your entertainment only: δss is fully-expanded form (not required) is

∆θL ∗ ∆θR ∗
( (v + βL ) − ∆βL ) − ( (v + βR ) − ∆βR )
θL θR
∆θL ∆θR
kL + kR + kL + kR
θL θR
The answer is correct, since plugging in zero into all the model mismatch terms into c causes c = 0, so
δss = 0 if there is no model mismatch. Compared to the open-loop result of δss = ±∞, the closed loop
1
δss = c is a much-desired improvement.
1−λ
What does this mean for the car? It means that the car will turn initially for a bit but eventually
converge to a fixed heading and keep going straight from there.

Contributors:

• Justin Yim.

• Tianrui Guo.

• Edward Wang.

EECS 16B, Fall 2017, Homework 8 11

You might also like