Let $f(x_1, \ldots, x_n)$ be a polynomial of degree 2 on $\mathbb R^n$, which can be written as $$ f(x_1, \ldots, x_n) = \sum_{i=1}^n\alpha_i x_i^2+\sum_{i=1}^n\sum_{j=i+1}^n\beta_{ij}x_ix_j, $$ where the coefficients $\{\alpha_i\}_{i=1}^n$ and $\{\beta_{ij}\}_{i=1,j>i}^n$ are real numbers.
I'm wondering if there is a way to verify whether $f$ can be written as a square, i.e., if there exist real coefficients $\{\gamma_i\}_{i=1}^n$ such that $$ f(x_1, \ldots, x_n) = \left(\sum_{i=1}^n \gamma_i x_i\right)^2. $$
Let us denote $A$ as a matrix that represents $f$ w.r.t the standard basis, meaning we have $f(x)= x^T A x$. Note $A$ isn't unique, and one might alter one element $i,j$ but change $j,i$ accordingly and we get the same polynomial.
Let's denote $c=[\gamma_1\ \cdots\ \gamma_n]^T$, then the second expression is $\left ( c^T x \right )^2$. Let's equate both ways of expressing $f$ and see what needs to happen $$x^T A x=(c^T x)^2 = (c^T x) (c^T x) = (x^T c)(c^T x) = x^T (cc^T)x$$ This means $A$ and $cc^T$ represent the same quadratic form. Using the fact $cc^T$ is symmetric, we can conclude that it is the symmetrization of $A$, meaning it is the only symmetric matrix which represents $f$ $$cc^T = \frac{A+A^T}{2}:=B$$ The right hand side is a matrix with $\alpha_i$s on the diagonal and $\frac{\beta_{ij}}{2}$ at elements $ij$ and $ji$. So to conclude, $f$ is a square of a linear combination iff its symmetric represntation is of the shape $$B = cc^T=\begin{bmatrix} \gamma_1 \gamma_1 & & \gamma_1 \gamma_n\\ & \ddots & \\ \gamma_n \gamma_1 & & \gamma_n \gamma_n \end{bmatrix}$$ Note we can solve this system under the assumption $\gamma_i \neq 0$ since otherwise we get a polynomial of less than $n$ variables. and we would have seen that in $f$, so I guess that you could denote $B$'s columns and get $$c = \frac{b_1}{\gamma_1} = \cdots = \frac{b_n}{\gamma_n}$$ From this you can get $c$ up to scaling $\alpha$.