Computes the next element of a tuple space.
[ rnk, x ] = intprb_tuplenext ( m1, m2, n, rnk, x )
a 1-by-1 matrix of doubles, integer value, the minimum entry.
a 1-by-1 matrix of doubles, integer value, the maximum entry.
a 1-by-1 matrix of doubles, integer value, positive, the number of components.
a 1-by-1 matrix of doubles, integer value, positive, the index of the tuple. On input, the index of the previous tuple. On output, the index of the next tuple.
a n-by-1 matrix of doubles, the tuple. On input, the previous tuple. On output, the next tuple.
This function produces the vector x, with n components, which have integer components in the range [m1,m1+1,...,m2]. The elements are n vectors. Each entry is constrained to lie between m1 and m2. The elements are produced one at a time. The first element is
(m1,m1,...,m1),
the second element is
(m1,m1,...,m1+1),
and the last element is
(m2,m2,...,m2).
Intermediate elements are produced in lexicographic order.
On first call, set the input argument rnk
to 0.
On subsequent calls, the input value of rnk
should
be the output value of rnk
from the previous call.
When there are no more elements, rnk
will be returned as 0.
This function is used in the intprb_corpeak
function.
// Displays all tuples of length 5 with elements between 0 and 1. x = []; rnk = 0; // Tuple #1: [ rnk, x ] = intprb_tuplenext ( 0, 1, 5, rnk, x ) // Tuple #2: [ rnk, x ] = intprb_tuplenext ( 0, 1, 5, rnk, x ) // Tuple #3: [ rnk, x ] = intprb_tuplenext ( 0, 1, 5, rnk, x ) // etc... // Displays all tuples of length 2 with elements between 1 and 3. n = 2; m1 = 1; m2 = 3; rnk = 0; x = []; computed = []; for i = 1 : 12 [ rnk, x ] = intprb_tuplenext ( m1, m2, n, rnk, x ); disp([rnk x']) end // Notice that the vector [0 0 0] announces that the end has been reached. // From there, the algorithm circles. | ![]() | ![]() |