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.