function [] = chap_1_prob_7(n) % % Written by: % -- % John L. Weatherwax 2007-07-01 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- %n = 10; % % Part (a): % % Verify that our estimate of the probabilities sum to one: % P_sum = 0; for ii=1:n, P_sum = P_sum + prob_select_keys_removed( ii, n ); end P_sum % Compute the expectation E[k]: % Exp = 0; for ii=1:n, Exp = Exp + ii*prob_select_keys_removed( ii, n ); end Exp % Compute the expectation squared E[k^2]: % Exp2 = 0; for ii=1:n, Exp2 = Exp2 + (ii^2)*prob_select_keys_removed( ii, n ); end Exp2 % Compute the variance: % Var = Exp2 - Exp^2 function p = prob_select_keys_removed( k, n ) switch k case 1, p = 1/n; case 2, p = (1-1/n)*(1/(n-1)); otherwise, p = 1; for ii=0:(k-2), p = p*( 1-1/(n-ii) ); end p = p*(1/(n-(k-1))); end