Language Reference

EXPANDGRID Function

EXPANDGRID (x1, x2 <, x3> …<, x15>) ;

This function is supported by the IML procedure and the iml action.

The EXPANDGRID function is part of the IMLMLIB library. The arguments to the EXPANDGRID function are k vectors, 2 less-than-or-equal-to k less-than-or-equal-to 15. The EXPANDGRID function returns a matrix that contains the Cartesian product of elements from the specified vectors. If the ith argument has n Subscript i elements, the return matrix has normal upper Pi Subscript i less-than-or-equal-to k Baseline n Subscript i rows and k columns.

Each row of the result contains a combination of elements of the input vectors. The first row contains the elements (x1[1], x2[1],…, xk[1]). The second row contains the elements (x1[1], x2[1],…, xk[2]). The first column varies the slowest, and the last column varies the fastest.

The following statement create a matrix of 0s and 1s. Each row is a vertex of the three-dimensional unit cube.

g = ExpandGrid(0:1, 0:1, 0:1);
print g;

Figure 147: A Cartesian Product of Three Vectors

g
000
001
010
011
100
101
110
111


You can use the EXPANDGRID function to generate a complete factorial design from the set of factors. You can also use it to evaluate a multivariate function on a dense grid of points. For example, the following statements evaluate the bivariate cubic polynomial f left-parenthesis x comma y right-parenthesis equals x cubed minus y squared minus 2 x plus 1 on a grid of points in the region left-bracket negative 2 comma 2 right-bracket times left-bracket negative 2 comma 2 right-bracket:

vx = do(-2, 2, 0.1);
vy = do(-2, 2, 0.1);
g = ExpandGrid(vx, vy);  /* grid on [-2,2] x [-2,2] */
x = g[,1]; y = g[,2];
z = x##3 - y##2 - 2#x + 1;
Last updated: July 20, 2026