pkg load statistics clear; %pkg load parallel L = 2.4 ; ARLc = 0 ; p_shift = 0.1 ; %%% initial p_shift value shift = 0.1 ; tic while( ARLc<= 369.8 || ARLc >=370.2 ) ARL = zeros(20000,1); % matlabpool open 4; % uses 4 cores in Matlab for s = 1:20000 ARL(s) = ARL_Fcn(L); % calling ARL_Fun code endfor % matlabpool close; ARLc = mean(ARL); % changing L value depending on ARLc if(ARLc < 370) if(((p_shift==shift)&&(shift<0.1))||p_shift == shift*2 || p_shift == shift*4 || p_shift == shift*8 ) fprintf(' ARLc < 370 %d %d next half shift %d\n',ARLc,L,shift/2) shift = shift /2 ; p_shift = shift ; L = L + shift ; else fprintf(' ARLc < 370 %d %d next shift %d\n',ARLc,L,shift) L = L + shift ; end else fprintf(' ARLc > 370 %d %d next decrement %d\n',ARLc,L,shift/2) shift = shift / 2; L = L - shift; end if(shift < 0.0001) break; end end toc