5.9 $\sin z+\sin 2 z+\sin 3 z=\cos z+\cos 2 z+\cos 3 z$.

Translate the above text into English, keeping the original text's line breaks and format, and output the translation result directly.

5.9 $\sin z+\sin 2 z+\sin 3 z=\cos z+\cos 2 z+\cos 3 z$.
5.9 Noting that $\sin z + \sin 3z = 2 \sin 2z \cos z$, and $\cos z + \cos 3z = 2 \cos 2z \cos z$, we have

$2 \sin 2z \cos z + \sin 2z = 2 \cos 2z \cos z + \cos 2z$

$\sin 2z (2 \cos z + 1) = \cos 2z (2 \cos z + 1)$

$(2 \cos z + 1)(\sin 2z - \cos 2z) = 0$.

Thus:

1) $2 \cos z + 1 = 0, \cos z = -\frac{1}{2}; z_1 = \frac{2\pi}{3}(3k \pm 1)$;
2) $\sin 2z = \cos 2z, \operatorname{tg} 2z = 1, 2z = \frac{\pi}{4} + \pi k; z_2 = \frac{\pi}{8}(4k + 1)$.

Answer: $z_1 = \frac{2\pi}{3}(3k \pm 1), z_2 = \frac{\pi}{4}(4k + 1), k \in \mathbb{Z}$.