TITLE: How to check whether a given matrix is in the image of a representation?
QUESTION [6 upvotes]: Let $G$ be a compact simple Lie group, and let $\rho$ be a (faithful, unitary) irreducible representation thereof of $\mathbb K$-dimension $n$, where $\mathbb K=\mathbb C/\mathbb R/\mathbb H$ if $R$ is real/complex/pseudo-real, respectively. It then follows that there is a subgroup of $SU(n)/SO(n)/Sp(n)$, respectively, isomorphic to $G$. One can think of $\rho$ as a map from $G$ to this subgroup.
How can I check whether a given matrix $M\in SU(n)/SO(n)/Sp(n)$ is in the image of $\rho$? In other words, given one such matrix $M$, how can I decide whether there exists some $g\in G$ such that $\rho(g)=M$?
For the sake of concreteness, say $G=G_2$ is the first exceptional simple group, and let $\rho$ be the representation with highest weight $2\omega_2$ (which is real and $27$-dimensional). This means that for any $g\in G_2$, $\rho(g)$ is a $27$-dimensional orthogonal matrix. If I take some arbitrary $27$-dimensional orthogonal matrix $M$, how can I check whether it can be written as $M=\rho(g)$ for some $g\in G_2$?
Note: I am particularly interested in the case where $M$ is diagonal, but I'd be interested in hearing about the general case as well. In the diagonal case, where everything is abelian, and one can essentially focus on a Cartan subalgebra, I assume one can be quite explicit about the image of $\rho$. In the general case, I wouldn't be surprised if one has to work harder.

REPLY [4 votes]: Suppose that $G$ is a compact Lie group (or, more generally, an algebraic group over some field $F$), ${\mathfrak g}$ is its Lie algebra. You are given a linear representation $\rho: G\to  GL(n, F)$. From this, compute the representation of the Lie algebra $\rho': {\mathfrak g}\to End(F^n)$. In fact, the representation $\rho$ is frequently given in terms of the highest weight of $\rho'$. Now, you check section 4.5 "Computing defining polynomials of an algebraic group in terms of its Lie algebra" in 
W. de Graaf, "Computing with Linear Algebraic Groups", CRC, 2017. 
He describes an algorithm for computing defining polynomial equations $p_i, i=1,...,N$, for $\rho(G)$ in terms of $\rho'({\mathfrak g})$ (more precisely, in terms of a basis for this subalgebra in $End(F^n)$). He even has software (check his webpage https://www.science.unitn.it/~degraaf/) for practical computations of this type. 
Lastly, to verify if the given matrix $A\in GL(n, F)$ belongs to $\rho(G)$, evaluate the polynomials $p_i$ on $A$.