I found myself in the same situation, had to find a real symmetric
square root $B$ of a real 3x3 symmetric positive definite matrix $A$,
and that, on a small board with basically no memory, javascript, and
very few libraries.
Note that if the matrix has negative eigenvalues, then there is at least
no symmetric and real square root.
First, find the eigen values, say $\lambda_1$, $\lambda_2$,
$\lambda_3$. Since the characteristic polynomial is of degree $3$,
we can find the roots numerically, using either roots or trigonometric
functions, see the wikipedia page for the cubic equation.
So, set $\mu_i = \sqrt{\lambda_i}$, and define an interpolating
polynomial
$$
q(t) = \frac{ (t-\lambda_2)(t-\lambda_3)}
{ (\lambda_1-\lambda_2)(\lambda_1-\lambda_3) } \mu_1 +
\frac{ (t-\lambda_3)(t-\lambda_1)}
{ (\lambda_1-\lambda_2)(\lambda_1-\lambda_3) } \mu_2 +
\frac{ (t-\lambda_1)(t-\lambda_2)}
{ (\lambda_1-\lambda_2)(\lambda_1-\lambda_3) } \mu_3
$$
and set
$$
B = q(A).
$$
We now note that if $v$ is an eigenvector for $A$ with eigenvalue
$\lambda_i$, then
$$
Bv = q(A)v = q(\lambda_i)v = \mu_iv
$$
and so $v$ is an eigenvector for $B$ with eigenvalue $\mu_i$. It follows
from this, since $B$ is diaonalizable, and so $\mathbb{R}^3$ is generated by
eigenvectors, that $B^2 = A$.
Note 1:
In this proof, you can really replace $\mu_i$ with any number, and get a
new matrix using the polynomial $q$. In particular, you can set $\mu_i =
\lambda^{a/b}$ to get a rational power of the matrix $A$.
Note 2:
In the formula for $q(t)$, we divide by differences of eigenvalues. As a
result, the $\lambda_i$ must be distict. This method must be modified
(simplified really) if there are only two or one eigenvalues. However,
if you are implementing this using floating numbers, and you end up with
eigenvalues that are very close, then you end up dividing and
multiplying with very small numbers, which can be a problem with
floating point arithmetic, I am not an expert on this, but be careful :)
Note 3:
This method works for matrices of any size, even nonsymmetric ones, as
long as they are diagonalizable. The only problem is finding the roots
of the characteristic polynomial, but there should exist simple
numerical methods for this (again, not an expert on that topic).
Note 4:
This result can be generalized to basically any matrix, nonsymmetric,
nondiagonalizable, etc. This is described in one of the answers here:
Find the square root of a matrix
sqrtmreturns.) – 2'5 9'2 Nov 27 '22 at 23:38sqrtm; it returns real entries, in my case, as well. – I. Mohamed Nov 28 '22 at 02:48