# Chain rule deriviation

Given gradient and hessian of $\phi$ and the first and second derivatives of $h$ I would like to find the gradient and hessian matrix of $f$

$f(x)=h(\phi(x))$

Where $f:R^n \longrightarrow R$

$\phi:R^n \longrightarrow R$

$h:R \longrightarrow R$

According to the chain rule: $\nabla f = h'(\phi(x))\nabla\phi(x)$ Is it correct and trivial and doesn't need any other proof? And how can I find the hessian of $f$?

• Well, yeah, the chain rule says exactly that, why should you need some other proof? And just compute all (mixed) second order partial derivatives to find the hessian – VanillaThunder Mar 31 '18 at 19:08
• you might have to use the chain rule again... – VanillaThunder Mar 31 '18 at 19:14
• @cbdes Please remember that you can choose an answer among the given if the OP is solved, more details here meta.stackexchange.com/questions/5234/… – gimusi Apr 3 '18 at 14:35

Since

$$f(x_1,x_2,...,x_n)=h(\phi(x_1,x_2,...,x_n))$$

by chain rule we have that

$$\frac{\partial f}{\partial x_i}=h'(\phi(\vec x))\frac{\partial \phi}{\partial x_i}\implies \nabla f(\vec x) = h'(\phi(\vec x))\nabla\phi(\vec x)$$

For the Hessian note that

$$\frac{\partial^2 f}{\partial x_i^2}=h''(\phi(\vec x))\left(\frac{\partial \phi}{\partial x_i}\right)^2+h'(\phi(\vec x))\frac{\partial^2 \phi}{\partial x_i^2}$$

$$\frac{\partial^2 f}{\partial x_ix_j}=h''(\phi(\vec x))\frac{\partial \phi}{\partial x_i}\frac{\partial \phi}{\partial x_j}+h'(\phi(\vec x))\frac{\partial^2 \phi}{\partial x_ix_j}$$