Let $n \in \mathbb{N} (n \neq 0)$ , $A$ a real $\mathbb{nxn}$ square matrix, and $\mathbf{c}$ a vector in $\mathbb{R}^{n}$. Consider a real function $h: \mathbb{R} \longrightarrow \mathbb{R}, h \in C^{2}(\mathbb{R})$, and introduce the function $g: \mathbb{R}^{n} \longrightarrow \mathbb{R}$, defined by $$ g(\mathbf{x})=h\left(\langle A x, A x\rangle\right)- \langle \mathbf{c}, \mathbf{x} \rangle, \quad \forall \mathbf{x} \in \mathbb{R}^{n} . $$ I want to compute $\nabla g$ and $H(g)$ (using only matrices and vector terms)
My partial attempt: $$ g^{\prime}(x)=h^{\prime}(\langle A x, A x\rangle) \cdot \text { term }-c $$
Now $ \langle A x, A x\rangle $ is a sum of terms of the form:
$$ \left(\sum_{i=1}^{n} a_{s i} x_{i}\right)\left(\sum_{i=1}^{n} a_{s i} x_{i}\right)=\sum_{k_{1}+k_{2}, \ldots+k_{n}=2}^{n}\left(\begin{array}{c} 2 \\ k_{1}, k_{2}, \ldots, k_{n} \end{array}\right) x^{k_{1}} \cdot \ldots \cdot x^{k_{n}} $$
How to continue? is there any option to avoid using so detailed form?
Thank you
The crux here is how to differentiate $f(x)=\langle Ax,Ax\rangle=\|Ax\|^2$. To do this, we just expand $$f(x+\eta)=\|A(x+\eta)\|^2=\|Ax\|^2+2\langle A\eta,Ax\rangle+\|A\eta\|^2=f(x)+2\eta^\top(A^\top Ax)+o(\|\eta\|).$$ So by the definition of the derivative, we have $\nabla f=2A^\top Ax$.