Language Reference


EXPANDGRID Function

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

The EXPANDGRID function is part of the IMLMLIB library . The arguments to the EXPANDGRID function are k vectors, $2 \leq k \leq 15$. The EXPANDGRID function returns a matrix that contains the Cartesian product of elements from the specified vectors. If the ith argument has $n_ i$ elements, the return matrix has $\Pi _{i\leq k}n_ 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 25.127: A Cartesian Product of Three Vectors

g
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1



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(x,y)=x^3 - y^2 - 2x + 1$ on a grid of points in the region $[-2,2]\times [-2,2]$:

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;