disp('Normal Likelihood -- Normal Prior')
  lw = 3; 
  set(0, 'DefaultAxesFontSize', 15);
  fs = 15;
  msize = 10;
% end of preabmle--------------------------------------


close all

data =[2.944,-13.361,7.143,16.235,-6.917,8.580,...
          12.540,-15.937,-14.409,5.711];
n = length(data);
xbar = mean(data); 

sigma2 = 100;
tau2 = 20;
mu = 20;
%-----------------------------------------------------------------
figure(1)
xx = xbar-4*sqrt(sigma2):(sqrt(sigma2)/50):xbar+4*sqrt(sigma2);
yy = 1/(sqrt(2 * pi * sigma2/n)) .* exp(-1./(2 *sigma2/n).* (xx - xbar).^2 );
plot(xx,yy,'b-','linewidth',lw)
hold on
xxxx= mu -4*sqrt(tau2):(sqrt(tau2)/50):mu+4*sqrt(tau2);
yyyy = 1/(sqrt(2 * pi * tau2)) .* exp(-1./(2 *tau2).* (xxxx - mu).^2 );
plot(xxxx,yyyy,'r-','linewidth',lw)
hold on
xxx=mu  -4*sqrt(tau2):(sqrt(tau2)/50):mu+4*sqrt(tau2);
lambda = tau2/(tau2 + sigma2/n);
pom = lambda * xbar + (1-lambda)*mu;
pov = sigma2/n * tau2/(tau2 + sigma2/n);
xxx= pom -4*sqrt(pov):(sqrt(pov)/50):pom+4*sqrt(pov);
yyy = 1/(sqrt(2 * pi * pov)) .* exp(-1./(2 *pov).* (xxx - pom).^2 );
plot(xxx,yyy,'g-','linewidth',lw)
legend('likelihood','prior','posterior',1)
xlabel('\theta')
axis([-15 37 0 0.17])
hold off
%print -depsc 'C:\Springer\Bayes\Bayeseps\bayesnorm.eps'
