function r = i4_to_halton_sequence ( ndim, n, step, seed, leap, base ) %% I4_TO_HALTON_SEQUENCE: next N elements of an NDIM-dimensional Halton sequence. % % Discussion: % % The NDIM-dimensional Halton sequence is really NDIM separate % sequences, each generated by a particular base. % % This routine selects elements of a "leaped" subsequence of the % Halton sequence. The subsequence elements are indexed by a % quantity called STEP, which starts at 0. The STEP-th subsequence % element is simply element % % SEED(1:NDIM) + STEP * LEAP(1:NDIM) % % of the original Halton sequence. % % Modified: % % 21 September 2004 % % Author: % % John Burkardt % % Reference: % % J H Halton, % On the efficiency of certain quasi-random sequences of points % in evaluating multi-dimensional integrals, % Numerische Mathematik, % Volume 2, 1960, pages 84-90. % % J H Halton, G B Smith, % Algorithm 247: Radical-Inverse Quasi-Random Point Sequence, % Communications of the ACM, % Volume 7, 1964, pages 701-702. % % Ladislav Kocis, William Whiten, % Computational Investigations of Low-Discrepancy Sequences, % ACM Transactions on Mathematical Software, % Volume 23, Number 2, 1997, pages 266-294. % % Parameters: % % Input, integer NDIM, the spatial dimension. % 1 <= NDIM is required. % % Input, integer N, the number of elements of the sequence. % % Input, integer STEP, the index of the subsequence element. % 0 <= STEP is required. % % Input, integer SEED(NDIM), the Halton sequence index corresponding % to STEP = 0. % % Input, integer LEAP(NDIM), the succesive jumps in the Halton sequence. % % Input, integer BASE(NDIM), the Halton bases. % % Output, double precision R(NDIM,N), the next N elements of the % leaped Halton subsequence, beginning with element STEP. % ndim = floor ( ndim ); n = floor ( n ); step = floor ( step ); seed(1:ndim) = floor ( seed(1:ndim) ); leap(1:ndim) = floor ( leap(1:ndim) ); base(1:ndim) = floor ( base(1:ndim) ); % % Check the input. % if ( ~halham_ndim_check ( ndim ) ) error ( 'I4_TO_HALTON_SEQUENCE - Fatal error!' ); end if ( ~halham_n_check ( n ) ) error ( 'I4_TO_HALTON_SEQUENCE - Fatal error!' ); end if ( ~halham_step_check ( step ) ) error ( 'I4_TO_HALTON_SEQUENCE - Fatal error!' ); end if ( ~halham_seed_check ( ndim, seed ) ) error ( 'I4_TO_HALTON_SEQUENCE - Fatal error!' ); end if ( ~halham_leap_check ( ndim, leap ) ) error ( 'I4_TO_HALTON_SEQUENCE - Fatal error!' ); end if ( ~halton_base_check ( ndim, base ) ) error ( 'I4_TO_HALTON_SEQUENCE - Fatal error!' ); end % % Calculate the data. % r(1:ndim,1:n) = 0.0; for i = 1: ndim seed2(1:n) = seed(i) + step * leap(i) : leap(i) : ... seed(i) + ( step + n - 1 ) * leap(i); base_inv = 1.0 / base(i); while ( any ( seed2 ~= 0 ) ) digit(1:n) = mod ( seed2(1:n), base(i) ); r(i,1:n) = r(i,1:n) + digit(1:n) * base_inv; base_inv = base_inv / base(i); seed2(1:n) = floor ( seed2(1:n) / base(i) ); end end