%this program calculates the 
%posterior distribution in the exponential-lognormal example. 

clear;
clc;
T = 25;
ybar = 1;
mu = 1;
sig = .5;

theta_grid = linspace(.0001,5,1000);
%density_a = (theta_grid.^T).*exp(-T*ybar*theta_grid);
%normc = trapz(theta_grid,density_a);
%density_final = density_a/normc
%plot(theta_grid,density_final)

density_prior = (1/sqrt(2*pi*sig))*(theta_grid.^(-1)).*...
    exp( - (1/(2*sig))*(log(theta_grid) - mu).^2 );
plot(theta_grid,density_prior,'r');
hold on;

density_a = theta_grid.^(T-1).* exp( - (1/(2*sig))* ( ...
    (log(theta_grid)-mu).^2 )- T*ybar*theta_grid );
normc = trapz(theta_grid,density_a);
density_final = (1/normc)*density_a;
plot(theta_grid,density_final)
hold off;