# Differentiate the squared dot product

I am new to Mathematics stack exchange community and has no experience in asking question so please bear with me. I am watching deep learning course from Coursera and encounter a question during the video. $$\left|\frac d{d\vec x}(\vec x\cdot\vec x)^2\right|=?$$ $$\vec x=\begin{bmatrix}x_1\\x_2\end{bmatrix}=\begin{bmatrix}3\\4\end{bmatrix}$$ I am not sure how to perform dot product on 2 vectors since they are 2x1 and 2x1 dimension. Please guide me! Thanks

Note: After some try and error, I got the answer, but I don't understand the solution.

• There is something wrong in the answer, Since you are calculating a |.|, it should be indicated as $$|4|\vec x|^2 \vec x|=4|\vec x|^3$$ – gimusi Dec 10 '17 at 14:39

By definition, the derivative of a scalar $f(x,y)$ with respect to a vector $(x,y)$ is the following vector $$\left(\frac{\partial f}{\partial x},\frac{\partial f}{\partial y}\right).$$

We have $$f(x_1,x_2)=(\vec x \cdot \vec x)^2 =\left(x_1^2+x_2^2\right)^2.$$

So the derivative in question is the vector $$(4(x_1^2+x_2^2)x_1,4(x_1^2+x_2^2)x_2).$$

At $(3,4)$, this is $$(300,400).$$

EDIT

Taking the absolute value:

$$|(300,400)|=\sqrt{300^2+400^2}=100\times5=500.$$

• Do you mind explain the solution provided? – Mervyn Lee Dec 10 '17 at 14:19
• If you visit the wiki article then yu will see the definition. I just computed the square of the dot product and took the partial derivatives as it was required by the definition. – zoli Dec 10 '17 at 14:45

Note that

$$(\vec x \cdot \vec x)^2=|\vec x|^4=(x_1^2+x_2^2)^2$$

Thus: $$\frac{d(\vec x \cdot \vec x)^2}{d\vec x} =\left(\frac{\partial(\vec x \cdot \vec x)^2}{\partial x_1},\frac{\partial(\vec x \cdot \vec x)^2}{\partial x_2}\right) =(4x_1(x_1^2+x_2^2),4x_2(x_1^2+x_2^2))$$

$$\left|\frac{d(\vec x \cdot \vec x)^2}{d\vec x} \right|=\sqrt{16x_1^2(x_1^2+x_2^2)^2+16x_2^2(x_1^2+x_2^2)^2}=4(x_1^2+x_2^2)^{\frac32}=4|\vec x|^3$$

You can also apply the ordinary rules using the product rule:

$$\frac{d(\vec x \cdot \vec x)^2}{d\vec x} =2(\vec x \cdot \vec x)\vec x+2(\vec x \cdot \vec x)\vec x=4\vec x|\vec x|^2$$