function y = variance_func(lam1,lam2,al) %function returns the variance of the number of components failing each %month with the given parameters basics_f s_r(1:(m)) = lam2+lam1*exp(-al*(0:m-1)); %the failure rate with the given parameters pfail(1:m) = 1-exp(-s_r(1:m)); %probability of a component prduced in month i is pfail(i) 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 pf = pfail(i); %each month of production has a different failure rate. for j=(i+1):(m+m2) %s_varKs(i,j) = (n*pf*((1-pf)^(j-i)))-(n*(pf^2)*((1-pf)^(2*(j-i-1)))) +(n*(pf^2)*((1-pf)^(j-i-1))); temp1 = log(n) + log(pf) + (j-i)*(-s_r(i)); temp2 = log(n) + 2*log(pf) + 2*(j-i-1)*(-s_r(i)); temp3 = log(n) + 2*log(pf) + (j-i-1)*(-s_r(i)); maxt = max([temp1 temp2 temp3]); temp = maxt + log(exp(temp1-maxt) - exp(temp2-maxt) + exp(temp3-maxt)); varKs(i,j) = exp(temp); end end varK(1:m+m2) = sum(varKs); y=varK; clear i j varKs pf