%create a matrix of variances for each random variable, Ks(i,j) of %components produced in month i that fails in month j. clear varKs varK basics_f 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 = 1-exp(-r(i)); %each month of production has a different failure rate. for j=(i+1):(m+m2) 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))); end end varK(1:m+m2) = sum(varKs); clear i j varKs pf