Related to this question, I am trying to compute the Hessian of $$ g(r, \theta) = [r\cos(\theta)]^{\top} A \, [r\cos(\theta)] = f(r, \theta) ^{\top} A \, f(r, \theta) \tag{$*$} $$ for $r, \theta \in \mathbb{R}^n$ and $A = A^{\top} \in \mathbb{R}^{n \times n}$ where $f(r, \theta) = r \cos(\theta)$ is computed component-wise. Ideally, I hope to obtain a form for the Hessian of ($*$) using Hadamard and Frobenius notation (I have had trouble computing the Hessian from the formula given here.
Here is my attempt at computing gradients, where $C_{\theta} := \text{diag}(\cos(\theta))$, $S_{\theta} := \text{diag}(\sin(\theta))$, and $R := \text{diag}(R)$. \begin{align} \nabla_{\theta}g &= \nabla_{\theta} \{ (\cos(\theta)^{\top}(R A R) \cos(\theta) \} \\ &= -S_{\theta} (R A R) \cos(\theta) \tag{1} \end{align} and \begin{align} \nabla_{r}g &= \nabla_{r} \{ r^{\top}(C_{\theta} A C_{\theta}) r \} \\ &= (C_{\theta} A C_{\theta}) r \tag{2} \end{align} Now, I'm having trouble computing the second order terms from (1) and (2). Specifically, I'm having trouble computing the Jacobians: $$ D_{\theta} \{ -S_{\theta} (R A R) \cos(\theta) \} $$ and $$ D_{\theta} \{ (C_{\theta} A C_{\theta}) r \}. $$ Is there a clean way of doing this? As an alternative, I tried applying the formula $$ D^2g_x = Df_x^{\top} (A + A^{\top}) Df_x + D^2f_x (A + A^{\top}) f(x) $$ (for $x := (x^{r}, x^{\theta})^{\top}$) but had difficulty working with the final $D^2f_x (A + A^{\top}) f(x)$ term.
Define some variables $$\eqalign{ c &= \cos(\theta), \quad C = {\rm Diag}(c) \cr s &= \sin(\theta), \quad S = {\rm Diag}(s), \quad R = {\rm Diag}(r) \cr f &= c\odot r \cr df &= c\odot dr - s\odot r\odot d\theta \cr b &= Af \cr db &= A\,df = AC\,dr - ARS\,d\theta \cr }$$ Write the g-function in terms of these new variables and find its differential. $$\eqalign{ g &= A:ff^T \cr dg &= A:(f\,df^T+df\,f^T) \cr &= (A+A^T):df\,f^T \cr &= 2b:df \cr &= 2b:c\odot dr - 2b:s\odot r\odot d\theta \cr &= 2c\odot b:dr - 2s\odot r\odot b:d\theta \cr }$$ So the two gradients are $$\eqalign{ g_r &= \frac{\partial g}{\partial r} = 2c\odot b \cr g_\theta &= \frac{\partial g}{\partial \theta} = -2s\odot r\odot b \cr }$$ Now find the differential and gradients of $g_r$ $$\eqalign{ dg_r &= 2C\,db + 2B\,dc \cr &= 2C(AC\,dr - ARS\,d\theta) - 2B(S\,d\theta) \cr &= 2CAC\,dr - 2(CARS+BS)\,d\theta \cr g_{rr} = \frac{\partial p}{\partial r} &= 2CAC \cr g_{r\theta} = \frac{\partial p}{\partial \theta} &= -2(CAR+B)S \cr }$$ Similarly, $g_{\theta\theta}$ and $g_{\theta r}$ can be calculated as the gradients of $g_\theta$