I'm doing Bayesian problem where I need to calculate a posterior function for distribution mean $\theta$.
The problem goes as follows: I have a data set $y_1, y_2, ..., y_n$ with each $y_i \sim N(\theta, \sigma^2 = 40).$ I'm given that $\frac1n\sum_{i=1}^n y_i = 150$ and that the prior distribution for $\theta$ is $p(\theta)=N(\mu_0=180, \tau_0^2=160).$ Derive the posterior distribution for $\theta$, i.e. $p(\theta|y)$.
I have no problem in this task except with evaluating the normalizing constant:
\begin{align}p(y)&=\int_{-\infty}^{\infty}p(y|\theta)p(\theta)\,d\theta\\&=\frac{1}{\sqrt{(2\pi\sigma^2)^n2\pi\tau_0^2}}\int_{-\infty}^{\infty}\exp\left(-\frac{1}{2}\left(\frac{1}{\tau_0^2}(\theta-\mu_0)^2+\frac{1}{\sigma^2} \sum_{i=1}^n(y_i-\theta)^2\right)\right)\,d\theta \end{align}
My question is: how can I evaluate the Gaussian integral above?
\begin{align}p(y)&=\int_{-\infty}^{\infty}p(y|\theta)p(\theta)\,d\theta\\&=\frac{1}{\sqrt{(2\pi\sigma^2)^n2\pi\tau_0^2}}\int_{-\infty}^{\infty}\exp\left(-\frac{1}{2}\left(\frac{1}{\tau_0^2}(\theta-\mu_0)^2+\frac{1}{\sigma^2} \sum_{i=1}^n(y_i-\theta)^2\right)\right)\,d\theta \end{align}
Notice that
$$\frac{1}{\tau_0^2}(\theta-\mu_0)^2+\frac{1}{\sigma^2} \sum_{i=1}^n(y_i-\theta)^2 $$
is a quadratic function with leading coefficient being positive in $\theta$ and hence we can write it in the form of $$\frac{(\theta -B)^2}{A^2} + C$$
Hence \begin{align}p(y)&= \frac{1}{\sqrt{(2\pi\sigma^2)^n2\pi\tau_0^2}}\int_{-\infty}^{\infty}\exp\left(-\frac{(\theta -B)^2}{2A^2} -\frac{C}{2}\right)\,d\theta \\&= \frac{\exp(-C/2)}{\sqrt{(2\pi\sigma^2)^n2\pi\tau_0^2}}\int_{-\infty}^{\infty}\exp\left(-\frac{(\theta -B)^2}{2A^2} \right)\,d\theta \\ &=\frac{\exp(-C/2)}{\sqrt{(2\pi\sigma^2)^n2\pi\tau_0^2}} \sqrt{2\pi A^2}\end{align}
Hence if it suffices to solve for $A$ and $C$ to solve for your problem.