I have been given this question and would just like some hints for how to get started.
A system of charges consists of +2q at the origin and -q at the two points $(0, 0, a) $ and $(0, 0, -a)$. Show that the potential is given by:
$\phi(r, \theta) =\frac{q}{4\pi\epsilon_0}(\frac{2}{r}-\frac{1}{\sqrt{r^2+a^2-2racos\theta}}-\frac{1}{\sqrt{r^2+a^2+2racos\theta}})$
where r is the distance from the origin and $\theta$ is the polar angle of the field point. Any help is greatly appreciated.
Hint:
if $\theta$ is the angle betwee the $z$ axis and the line passing thorough the origin and the point $P=(x,y,z)$ and $r$ is the distance $\overline{OP}$, than The distance from $P$ to the point $(0,0,a)$ is: $$ \sqrt{x^2+y^2+(z-a)^2}=\sqrt{x^2+y^2+z^2+a^2-2za}=\sqrt{r^2+a^2-2ar\cos \theta} $$ (because $z=r\cos \theta$).
Analogously you can find the distance from the oter charge in $(0,0,-a)$. Than use the fact that the potential is an additive function as noted in the comments.