% process(n) generates a sequence of n independent, identically distributed % random variables and displays various random sequences derived from it. function [void] = process(n) clf m = 10; % dependence on the past Z = rand(n+2*m,1); % iid random variables a = (0.5).^(1:m); % smoothing parameters a = a/sum(a); % normalize b = (0.9).^(1:m); % smoothing parameters b = b/sum(b); % normalize for i=1:n, X(i) = max(Z(i+m-4:i+m)); % recent maximum W(i) = median(Z(i+m-5:i+m+5)); % median within a window Y(i) = a * Z(i+1:i+m); % smoothed version of past values of Z V(i) = b * Z(i+1:i+m); % smoothed version of past values of Z end subplot(5,1,1) plot(1:n,Z(m+1:m+n),'.','markersize',12); axis([0 n 0 1]); title('Values of Z are independent Uniform(0,1) random variables') subplot(5,1,2) plot(1:n,X,'.','markersize',12); axis([0 n 0 1]); title('Maximum of last 5 values of Z') subplot(5,1,3) plot(1:n,W,'.','markersize',12); axis([0 n 0 1]); title('Median of nearest 11 values of Z') subplot(5,1,4) plot(1:n,Y,'.','markersize',12); axis([0 n 0 1]); title('Weakly smoothed version of last 10 values of Z') subplot(5,1,5) plot(1:n,V,'.','markersize',12); axis([0 n 0 1]); title('Strongly smoothed version of last 10 values of Z')