# Struggling to interpret exam past paper question, calculus and vectors involved.

I hate to do this but there are no solutions and I am really struggling to interpret what it means.

$f:\mathbb{R}^3\to\mathbb{R}$, $f(X)=\|X \|^2$ ($X=$ the vector $(x,y,z)$) and $P:\mathbb{R}^3\to\mathbb{R}^3$ $P(X) = A\times X$ where $A$ is the vector $(a_1,a_2,a_3)$ (constant)

a) Calculate gradient $\nabla f(X)$

I got $(2x,2y,2z)$ which I am pretty sure is fine (I'd love a "yeah it is"), this makes sense, because $\| X\|^2$ is "radius squared" and this vector is in the direction "pointing away from" the origin in the direction $x,y,z$.

It passes the "sanity check" basically.

b) calculate the 3x3 matrix $DP(X)$ well $A\times X$ is: \begin{pmatrix} a_2 z - a_3 y\\ a_1 z - a_3 x\\ a_1 y - a_2 x\\ \end{pmatrix}

so a row in the matrix is the change in the row in $P(X)$ wrt x, y and z.

This gives: \begin{pmatrix}0 & -a_3 & a_2 \\ -a_3 & 0 & a_1 \\-a_2 & a_1 & 0\end{pmatrix}

(I'd love a "that's right" here too)

so I'm fine with that.... here's the question

c) using the chain rule or otherwise, show that $\nabla (f\circ P)(X) = 2\|A\|^2 X - 2(A\cdot X)A$

where T is the upside down triangle. the @ sign denotes composition

DOES IT MEAN: "gradient of (f(P(x)))" "Tf(P(X))" we worked out Tf in part a (2x,2y,2z) = 2(x,y,z) so 2P(X)....

Why the chain rule? Where does differentiation come into play?

I've probably missed something simple, but yes, quite unsure of this part c.

-
Welcome to MSE! It really helps readability to format questions using MathJax (see FAQ). Regards – Amzoti Jun 2 '13 at 18:18
I made a few edits which may indicate how to proceed... – copper.hat Jun 2 '13 at 18:19
Thanks guys, I edited right afterwards to preserve the format, but that's A LOT better, thanks for clearing it up, forgive my old "Yahoo Answers" ways (I joined, went back there, now I'm here again). @copper.hat – Alec Teal Jun 2 '13 at 18:26
Matrix can be done by \begin{pmatrix}0 & -a_3 & a_2 \\ -a_3 & 0 & a_1 \\-a_2 & a_1 & 0\end{pmatrix}: $$\begin{pmatrix}0 & -a_3 & a_2 \\ -a_3 & 0 & a_1 \\-a_2 & a_1 & 0\end{pmatrix}$$ – Shuhao Cao Jun 2 '13 at 18:30
@f.nasim DP(X) is the Jacobian Matrix of P(X), partial P(X) / partial X is a way of writing it (X is a vector remember) Thanks. – Alec Teal Jun 2 '13 at 18:42

a) It's ok. No need for sanity checks, as $\nabla f(X)=\begin{pmatrix}\partial_x f\\\partial_y f\\\partial_z f \end{pmatrix}=\begin{pmatrix}\partial_x (x^2+y^2+z^2)\\\partial_y (x^2+y^2+z^2)\\\partial_z (x^2+y^2+z^2) \end{pmatrix}=\begin{pmatrix}2x\\2y\\2z \end{pmatrix}$. b) Here you should obtain a different result. There is an "intuition" rule:

$\displaystyle A\times X = \det\begin{pmatrix}\vec e_x&\vec e_y&\vec e_z\\a_1&a_2&a_3\\x&y&z\end{pmatrix} =\vec e_x(za_2-ya_3)+\vec e_y(xa_3-za_1)+\vec e_z(ya_1-xa_2)=\begin{pmatrix}za_2-ya_3\\xa_3-za_1\\ya_1-xa_2\end{pmatrix}.$

Hence your $DP(X)$ gradient is \begin{pmatrix}0&-a_3&a_2\\a_3&0&-a_1\\-a_2&a_1&0\end{pmatrix}

c) Here you can either write the expression explicitly:

$\nabla(f\circ P)(X) = \nabla ((za_2-ya_3)^2+(xa_3-za_1)^2+(ya_1-xa_2)^2)$

$=\begin{pmatrix}2xa_3^2-2a_1a_3z+2xa_2^2-2ya_1a_2\\ 2ya_3^2+2ya_1^2-2xa_1a_2-2za_2a_3\\ 2za_2^2+2za_1^2-2xa_3a_1-2ya_2a_3\end{pmatrix}=2\|A\|^2X - 2\begin{pmatrix} a_1a_1x+ a_1a_3z+ ya_1a_2\\ ya_2a_2 +xa_1a_2+za_2a_3\\ za_3a_3xa_3a_1+ya_2a_3\end{pmatrix}$

$= 2\|A\|^2X - 2(A\cdot X)A$.

or you can use the chain rule $\nabla (f\circ P)(X) = \nabla f (P(X))\circ DP(X) = 2P(X)\circ DP$ to arrive to the same result as Ros suggested.

It's up to you to decide which way is faster/safer for you.

EDIT On the chain rule: (I can see why there could be some difficulties here, I'll try to stay simple).

Let's say, we note $P_i$ - the elements of the vector $P(X)$ and $\vec e_i$ - unitary basis, so $P(X) = \sum_{i=1}^3 P_i \vec e_i$. Additionaly, we will note our coordinates as $x_i$; it might be useful for future, when the dimension becomes arbitrary and/or you study tensors. Then $f(P(X)) = \sum_{i=1}^3 P_i^2$.

The gradient of an arbitrary function writes $\nabla g(X) = \sum_i \partial_{x_i}g(X)\cdot \vec e_i$, so in our case

$\nabla (f (P(X)) =\sum_{i=1}^3\partial_{x_j}(f(P(X)))\vec e_j = \sum_{i=1}^3\sum_{j=1}^3\partial_{P_i}(f(P ))\partial_{x_j}P_i(X)\vec e_j$

$=\displaystyle \sum_{i=1}^3\sum_{j=1}^3 2P_i\partial_{x_j} P_i \cdot \vec e_j$

On the other hand, the elements of the matrix $(DP)_{ij}$ are found as $\partial _{x_j}P_i$, so it's now easy to interpet the required gradient as $\nabla f(P(X)) DP(X) = 2P(X) DP(X)$, where the first factor is seen as a row-vector and the second one - a square matrix.

Another simplification closely related to the nature of vector product is that $\forall X \, A\times X = DP\cdot X$ (the last one is a product of a square matrix and a vector), and $DP^T=-DP$. It allows to say that

$(2P(X) DP(X))^T = -2DP(X) P(X) \text{(last term seen as a column vector)} = -2A\times (A\times X)$. By a so-called "vector triple product rule" (cf. wikipedia), it simplifies into $2((A\cdot A)X-(A\cdot X)A)$, which is exactly the desired result.

-
I feel much sillier now because ... well I get all of that and feel silly :P, I do however not get the chain rule as you've applied it there, looking at types alone: 2P(X) gives a 3x1 matrix (Vector), DP is a 3x3 matrix though. I think my issue lies with notation, which I ought to know, but if you wouldn't mind finishing that chain rule step, I'd be very appreciative. – Alec Teal Jun 2 '13 at 21:55
b) Should be $M=\begin{pmatrix}0 & -a_3 & a_2 \\ a_3 & 0 & -a_1 \\-a_2 & a_1 & 0\end{pmatrix}$. The easiest way to see this, is that it is precisely the matrix expression for the cross product: $A \times X = MX$.
c) I guess that you're asked to compute $\nabla (f \circ P) (X)$. You can do it by using chain rule: $\nabla (f \circ P) (X) = \nabla f (PX) DP(X)$ which you can check it is equal to ($-2A\times (A\times X)$ and to) the required expression by a direct computation.
Another way to proceed is to explicitly write $f \circ P$ and then deduce its derivative (it would be painful).