It is known that $\cos n \theta $ is a polynomial of $\cos \theta $. This polynomial is the so called Chebyshev polynomial of order $n$, often denoted as $T_n(x)$.
We have the recursion relation
$$T_{n+1} (x) = 2 x T_n(x) - T_{n-1} (x) $$
with $T_0(x) = 1$, $T_1(x) = x$. This recursion relation suggests an iterative algorithm for calculating $T_n(x)$ for a specific value of $x$. But there is no guarantee that the algorithm is numerically stable. However, it is! Below is my code. I use two algorithms to calculate $\cos(N\theta )$, one directly and the other iteratively. They agree to machine precision.
Why is it stable?
theta = pi* sqrt(5);
N = 2000;
f1 = zeros(N, 1);
f1(1) = 1;
f1(2) = cos(theta);
f2 = cos((N-1)*theta);
for s = 3 : N
f1(s) = 2* cos(theta)*f1(s-1) - f1(s-2);
end
abs(f1(end) - f2)