Vectors, Arrays, Matrices Exercise 1


#1

Author: Willem Hekman

Hello all,

I had a quick preview of the material this weekend.

Unfortunately the exercise at the end of the chapter on vectors and arrays felt like it came dropping out of the air.
It was not clear to me what this SDE is all about, what is the context? :frowning:

I must say it is the first SDE I have ever encountered: It is not clear to me what “A” stands for (what are its dimensions?), same for the other symbols in the equation.

Any leads? Maybe the exercise can be improved?

  • Willem

#2

Hi. “A” will be a matrix here. More specifically the dimensions of everything are:

  • X_t is an n-vector
  • b is an n-vector
  • A is an nxn matrix
  • W_t is a k-vector
  • \Sigma is an nxk matrix.

I think the goal of this exercise is mostly to give people a chance to experiment with some of the matrix operations described in the lecture. This is an application that will arise in more detail later – Specifically in the Linear State Space lecture and Linear Quadratic lectures.


#3

HI Willem,

Thanks for your feedback, it’s appreciated.

I guess you’re looking on the Julia side, at this page? I can see your point.

It’s pretty much as Chase says, although it could be much clearer. I’ll make some changes to help clarify.

Regards, John.


#4

Author: Willem Hekman

Hi John,

Thanks for the quick reply. Indeed it was that page.

A little additional information over there would be great:

Looking at the solutions it seems like it should be an easy exercise using Julia.

With some context on the elements in the equation the approach should be straightforward.

-Willem


#5

Author: Willem Hekman

Hi Chase,

Good to know that more information can be found in those sections.

When it comes to experimenting with the matrix operations explained in this explanaton on Julia syntax a helping hand would be great.

To me it seemed appropriate if in this chapter students would only have to just focus on appropriate use of the Julia syntax in the context of quantitatice economics: that is to say, with the - to a large audience, new - math theory already written out for the most part.

-Willem


#6

Author: Willem Hekman

Hey John, Chase,

I had a closer look at the section yesterday and want to say I really appreciate the effort that went into making it.

To offer something in return, in case you are interested, I’ve written out the derivation of the solution in mathjax/latex that can be copy/pasted into Jupyter.

Feel free to use it for the course, it would be an honor.

Here it is:

We have an optimization problem:

$$ v(x) = \max_{x,u} { -y’Py - u’Qu } $$

s.t.

$$ y = Ax + Bu $$

with

  • $P > 0$, symmetric, an $n \times n$ matrix.

  • $Q > 0$, symmetric, an $m \times m$ matrix.

  • $B$ an $n \times m$ matrix.

  • $x$ an $n \times 1$ matrix.

  • $y$ an $m \times 1$ matrix.

The associated Lagrangian:

$$L = -y’Py - u’Qu + \lambda’ \lbrack Ax + Bu - y \rbrack$$

1.

Differentiating w.r.t y - and setting this derivative equal to zero - yields

$$ \frac{ \partial L}{\partial y} = - 2 \cdot y’P’ - \lambda’ = 0 :.$$

Accordingly

$$ \lambda = -2 Py $$

Notice, for the above we make use of the fact that $P$ is symmetric.

2.

Differentiating w.r.t. u - and setting this derivative equal to zero - yields

$$ \frac{ \partial L}{\partial u} = - 2 \cdot u’Q + \lambda’B = 0 :.$$

substituting $\lambda$ gives

$$ u’Q + y’PB = 0 :.$$

Taking the transpose (using $P’=P$, $Q’=Q$) gives

$$ B’Py + Qu = 0 :.$$

Substituting for $y$, $y = Ax + Bu$, gives

$$ B’P(Ax + Bu) + Qu = 0 :.$$

$$ B’PAx + (B’PB + Q)u = 0$$

so

$$ u = -(B’PB + Q)^{-1}B’PAx $$

To clean up these equations, let us define

$$R:=(B’PB + Q)^{-1}:.$$

Notice that

$$R’ = ((B’PB + Q)^{-1})’ = $$

$$((B’PB + Q)’)^{-1} = (B’PB + Q)^{-1} = R $$

That way

$$ u = -RB’PAx $$

Then let us define

$$ S = RB’PA $$

such that

$$ u = -Sx $$

is optimal.

3.

We have found the following “optimal coordinates”

$$ u(x) = -Sx $$

and

$$ y(x) = Ax + Bu = Ax - BSx = (A - BS)x :.$$

To evaluate the function

$$v(x)= - y’Py - u’Qu$$

at these coordinates,

let us first write out

$$y’Py = $$

$$((A - BS)x)'P(A - BS)x = $$

$$ x’(A’ - S’B’)P(A - BS)x = $$

$$ x’A’PAx $$

$$ -x’A’PBSx$$

$$ -x’S’B’PAx$$

$$ +x’S’B’PBSx $$

Notice that the 2nd and 3rd term are each others transpose.

Now let us write out

$$u’Qu = $$

$$ x’S’QSx = x’(RB’PA)'Q(RB’PA)x = $$

$$ x’A’PB(RQR)B’PAx $$

Now the cool part:

If we add $y’Py$ and $u’Qu$ we will see some terms cancel:

$$ y’Py + u’Qu = $$

$$ x’A’PAx $$

$$ -x’A’PBSx $$

$$ -x’S’B’PAx $$

$$ +x’S’(B’PB + Q)Sx :.$$

Notice, the last term contains parts of $y’Py$ and $u’Qu$.

Remember

$$ R := (B’PB + Q)^{-1} $$

and $$ S : = RB’PA :.$$

On closer inspection the last term

$$ x’S’(B’PB + Q)Sx = $$

$$ x’S’R^{-1}Sx =$$

$$ x’(A’PBR) : R^{-1} : Sx = $$

$$ x’A’PBSx$$

cancels with the second term.

Thus the solution to the optimization problem is

$$ -v(x) = y’Py + u’Qu = $$

$$ x’A’PAx - x’S’B’PAx = $$

$$ x’ (A’PA - A’PB(B’PB+Q)^{-1}B’PA) x :=$$

$$ x’\tilde{P}x$$


That finishes the derivation. Btw, I read that you like Kyuss, must also be one of my favorites!

Now I`ll continue with the next chapter :slight_smile:


#7

Cool, thanks Willem!

I had a quick read and it looks spot on.

Right now I’m busy doing a bunch of stuff with the QuantEcon organization and writing up my own papers, but I’ll pass this on to my RAs to double check, and then, assuming it’s all good we’ll post it as a solution.

If you have a personal web page that I can link to then I’ll give you credit on the notebook that we publish. Please let me know.

You like Julia, maths and Kyuss, so I see you have excellent taste. It’s good to see. Recently I’ve been listening to ‘The Heavy Eyes’. They’re not Kyuss but still pretty good.

Regards, John.


#8

Your solution is now up Willem. Thanks again:

http://nbviewer.jupyter.org/github/QuantEcon/QuantEcon.applications/blob/master/linear_algebra/linear_algebra_solutions.ipynb

(My PhD student Guanlong Ren made some small modifications.)


#9

Author: Willem Hekman

Thanks John, Guanlong, looks great:) In case you feel like adding it, my personal webpage is: willemhekman.nl


#10

Done:

https://github.com/QuantEcon/QuantEcon.applications/blob/master/linear_algebra/linear_algebra_solutions.ipynb