function y = expected(lam1,lam2, al) %create a matrix of expected values for #components produced in month i %that fails in month j (fail in ((j-1),j)) j=1:m+m2, i=1:m basics_f s_r(1:(m)) = lam2+lam1*exp(-al*(0:m-1)); pfail(1:m) = 1-exp(-s_r(1:m)); for i=1:m %for each month of production i, calculate the expected number of components that were produced in that month, that fail in each month j xks(i,:) = 0; pf = pfail(i); %each month of production has a different failure rate. for j=(i+1):(m+m2) temp = (j-i-1)*(-s_r(i)) + log(pf); xks(i,j) = n*exp(temp); end end xK(1:(m+m2)) = sum(xks(:,(1:m+m2))); y=xK; clear i j pf xKs