# Derivative of gradient of vector wrt vector

I am trying to solve for the derivative of the following equation:

$$t(\pmb {m_1} , \pmb {m_2} )= \frac{1}{2} \: ||\nabla \pmb {m_1} ||_2^2 \: ||\nabla \pmb {m_2}||_2^2 \: - \frac{1}{2} \:|\nabla \pmb {m_1} \cdot \nabla \pmb {m_2} |^2$$

where $$\pmb {m_1}$$ and $$\pmb {m_2}$$ are matrices that have been vectorized, and $$\nabla \pmb {m_1}$$, $$\nabla \pmb {m_2}$$ are the gradients that have been vectorized as well. Gradients are calculated using finite difference along x, y and z dimensions.

Basically, I am trying to solve for $$\frac {\partial t}{\partial \pmb {m_1}}$$ and $$\frac {\partial t}{\partial \pmb {m_2}}$$.

So far I have this:

$$\frac {\partial t}{\partial \pmb {m_1}} = (\nabla \pmb {m_1} \cdot \frac {\partial \nabla \pmb {m_1}}{\partial \pmb {m_1}}) \: ||\nabla \pmb {m_2}||_2^2 \: - (\nabla \pmb {m_1} \cdot \nabla \pmb {m_2})\cdot(\frac {\partial \nabla \pmb {m_1}}{\partial \pmb {m_1}} \cdot \nabla \pmb {m_2})$$

$$\frac {\partial t}{\partial \pmb {m_2}} = (\nabla \pmb {m_2} \cdot \frac {\partial \nabla \pmb {m_2}}{\partial \pmb {m_2}}) \: ||\nabla \pmb {m_1}||_2^2 \: - (\nabla \pmb {m_1} \cdot \nabla \pmb {m_2})\cdot(\frac {\partial \nabla \pmb {m_2}}{\partial \pmb {m_2}} \cdot \nabla \pmb {m_1})$$

I have trouble understanding $$\frac {\partial \nabla \pmb {m_1}}{\partial \pmb {m_1}}$$ and $$\frac {\partial \nabla \pmb {m_2}}{\partial \pmb {m_2}}$$

My intuition tells me these just equal to $$I$$ (the identity matrix), but I am not sure how to prove it.

This is how I have proceeded so far.

$$\frac {\partial \nabla \pmb m}{\partial \pmb m} = \left [\begin{matrix} \frac {\partial \nabla_1}{\partial m_1} & \frac {\partial \nabla_1}{\partial m_2} & \cdots & \frac {\partial \nabla_1}{\partial m_M} \\ \frac {\partial \nabla_2}{\partial m_1} & \frac {\partial \nabla_2}{\partial m_1} & \cdots & \frac {\partial \nabla_2}{\partial m_M} \\ \vdots & \vdots & \ddots & \vdots \\ \frac {\partial \nabla_M}{\partial m_1} & \frac {\partial \nabla_M}{\partial m_2} & \cdots & \frac {\partial \nabla_M}{\partial m_M} \end{matrix} \right ]$$

where,

$$\nabla_1 = (\frac {\partial m_1}{\partial x}, \frac {\partial m_1}{\partial y}, \frac {\partial m_1}{\partial z})$$

$$\nabla_2 = (\frac {\partial m_2}{\partial x}, \frac {\partial m_2}{\partial y}, \frac {\partial m_2}{\partial z})$$

...

...

$$\nabla_M = (\frac {\partial m_M}{\partial x}, \frac {\partial m_M}{\partial y}, \frac {\partial m_M}{\partial z})$$

which leads me to think that it is equal to 1 along the diagonal and 0 everywhere else.

Anyone who has experience with these problems, could you please help me? Otherwise, it would be deeply appreciated if you could refer me to any references where I can look deeper into this.

Thank you.