% eda05_02
% Illustrate the product of twos Normal distributions

% set up vectors da and d2
L=40;
Dd = 1.0;
d1 = Dd*[0:L-1]';
d2 = Dd*[0:L-1]';

% first normal distribution
d1bar=15;
d2bar=15;
C=[[10,8]',[8,10]'];
CI=inv(C);
norm=1/(2*pi*sqrt(det(C)));
Pa=zeros(L,L);
for i = [1:L]
for j = [1:L]
   dd = [d1(i)-d1bar, d2(j)-d2bar]';
   Pa(i,j)=norm*exp( -0.5 * dd' * CI * dd );
end
end

% second normal distribution
d1bar=15;
d2bar=25;
C=[[10,-8]',[-8,10]'];
CI=inv(C);
norm=1/(2*pi*sqrt(det(C)));
Pb=zeros(L,L);
for i = [1:L]
for j = [1:L]
   dd = [d1(i)-d1bar, d2(j)-d2bar]';
   Pb(i,j)=norm*exp( -0.5 * dd' * CI * dd );
end
end

% product, normalized to unit area
Pc=Pa.*Pb;
norm = (Dd^2)*sum(sum(Pc));
Pc = Pc/norm;

% plot results
eda_draw(Pa,'caption Pa',Pb,'caption Pb',Pc,'caption Pc');

