% MS-A0503 L3A demo % Room counts in households, taking a sample of two households. % (Matlab code) px = [.5 .2 .1 .1 .1]; py = px; % same distribution % Find out the probabilities for X+Y=s, % for all possible values of s. ps = zeros(1,10); for s=2:10 % What are the choices for x+y = s? for x=1:5 y = s-x; if y>=1 && y<=5 ps(s) = ps(s) + px(x)*py(y); end end end subplot(1,3,1) bar(1:5,px) xlabel('x') subplot(1,3,2) bar(1:5,py) xlabel('y') subplot(1,3,3) bar(1:10,ps) xlabel('s')