Example 7 Solve the equation
$$
\sqrt{x^{2}+\sqrt{3} x+\frac{7}{4}}+\sqrt{x^{2}-3 \sqrt{3} x+\frac{31}{4}}=4 \text {. }
$$
By the triangle inequality, we have
$$
\begin{array}{l}
\sqrt{\left(x+\frac{\sqrt{3}}{2}\right)^{2}+1^{2}}+\sqrt{\left(x-\frac{3 \sqrt{3}}{2}\right)^{2}+(-1)^{2}} \\
\geqslant \sqrt{\left[\left(x+\frac{\sqrt{3}}{2}\right)-\left(x-\frac{3 \sqrt{3}}{2}\right)\right]^{2}+[1-(-1)]^{2}} \\
=4 .
\end{array}
$$

Equality holds if and only if \( x+\frac{\sqrt{3}}{2}+x-\frac{3 \sqrt{3}}{2}=0 \).
Solving for \( x \) gives \( x=\frac{\sqrt{3}}{2} \).