function arlv = ARL_Fcn(L) % generate 5000 observations based on "mu" and "covarince" p = 2 ; % no of multivariate measurements lamda = .2 ; omega = .2 ; Mu = [0 0]; cov_matrix = [1 0; 0 1]; x = zeros(5000,2); simulate = mvnrnd(Mu,cov_matrix,5000); % generate multivariate data for j=1:2 % data transformation x(:,j) = (simulate(:,j)-Mu(:,j))./sqrt(cov_matrix(j,j)) ; end for t = 1:5000 Identity = eye (t); % creat an t*t identity matrix M = zeros(t,t); for i = 1:t % compute matrix M for j = 1:t if (j==i) M(j,i) = lamda ; elseif (j>=i) M(j,i) = lamda*(1-lamda)^(j-i); end end end I_M = Identity - M ; % Compute I-M ci = zeros(t,t); for i = 1:t % Computation of Ci matrix if (i==1) ci(i,i) = (1-omega)^(t-1); else ci(i,i) = omega*(1-omega)^(t-i); end end Q = I_M'*ci*I_M ; % compute Q Vt = x(1:t,:)'*Q*x(1:t,:) ; % compute Vt LCL_MV = p*trace(Q) - L*sqrt(2*p*(sum(Q(:).^2))) ; % limits varies depending on number of variables UCL_MV = p*trace(Q) + L*sqrt(2*p*(sum(Q(:).^2))); if ((trace(Vt)>= UCL_MV) || (trace(Vt) <= LCL_MV)) % the value will return depend on this condition arlv = t ; break; end end end