% eda03_09
% Illustrate a joint distribution and the two univariate
% distributions formed from it

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

% make a Normal distribution centered at d1bar, d2bar
d1bar=10;
d2bar=20;
s1=5;
s2=5;
P=exp(-((d1-d1bar).^2)/(2*s1*s1)) * exp(-((d2-d2bar).^2)/(2*s1*s1))';
P = P / (Dd*Dd*sum(sum(P))); % normalize

% sum along columna, which integrates P along d2 to get p(d1)
p1 = Dd*sum(P,2);

% sum along rows, which integrates p along d2 to get p(d2)
p2 = Dd*sum(P,1)';

% use simple drawing function that encapsulates all the graphics
eda_draw(P,'caption p(d1,d2)','       ',p1,'caption p(d1)','       ',p2,'caption p(d2)');
