% LMex030307_4th.m
% Example 3.3.7 
% Acme Industries builds 3 generators daily. Probability of a generator
% failing and needing to be retooled is 0.05. If a generator is shipped,
% the company earns $10,000, if it is retooled, the cost is $2000
% p_x(k) = the company's daily profit;
% Written 1/12/11 for EEOS601 by Eugene.Gallagher@umb.edu
% http://alpha.es.umb.edu/faculty/edg/files/edgwebp.html
n=3;
pfail=0.05;ppass=1-pfail;
profit=1e4;
retool=-2e3;
k=0:3;
p_xk=binopdf(k,3,ppass);
Profit=zeros(1,4); % initialize the results vector
for defects=0:3
    Profit(defects+1)=defects*retool+(3-defects)*profit;
end
disp('        Table 3.3.4')
disp('  No.')
disp('Defects  k=Profit     p_x(k)');
Out=[0:3;Profit;fliplr(p_xk)];
fprintf('%1.0f         $%5.0f     %8.6f\n',Out)