We are given
\[
x+\frac{1}{x}=2\cos\theta.
\]
Here \(x\) is real and \(x\neq 0\).
For real \(x\), we know that:
\[
x+\frac{1}{x}\geq 2 \quad \text{if } x>0.
\]
Also,
\[
x+\frac{1}{x}\leq -2 \quad \text{if } x<0.
\]
Therefore, for real \(x\),
\[
x+\frac{1}{x}\in (-\infty,-2]\cup [2,\infty).
\]
But the right-hand side is
\[
2\cos\theta.
\]
Since
\[
-1\leq \cos\theta \leq 1,
\]
we have
\[
-2\leq 2\cos\theta \leq 2.
\]
Now both conditions must be satisfied:
\[
x+\frac{1}{x}=2\cos\theta.
\]
The only possible values common to both ranges are
\[
2 \quad \text{and} \quad -2.
\]
Therefore,
\[
2\cos\theta=2
\]
or
\[
2\cos\theta=-2.
\]
So,
\[
\cos\theta=1
\]
or
\[
\cos\theta=-1.
\]
Hence,
\[
\cos\theta=\pm 1.
\]