Completing the square of complicated expression (answer available)

27 Views Asked by At

I would like to rewrite the following expression

$$ \begin{align} \frac{1}{\sigma_{\theta}^{2}}\sum_{i=1}^{I}(\theta_{i}-\mu)^{2} + \frac{1}{\sigma_{0}^{2}}(\mu-\mu_{0})^{2} \end{align} $$

as a square with respect to $\mu$. I do not know how to complete the square, the answer should be

$$ \begin{align} \frac{\left(\mu - \frac{\sigma_{0}^{2}\sum_{i=1}^{I}\theta_{i}+\sigma_{\theta}^{2}\mu_{0}}{\sigma_{0}^{2} + \sigma_{\theta}^{2}}\right)^{2}}{\frac{\sigma_{\theta}^{2}\sigma_{0}^{2}}{\sigma_{0}^{2} + \sigma_{\theta}^{2}}}. \end{align} $$

What is the first step to do this? Write out the sum, or is there some trick?