EXPANDGRID (x1, x2 <, x3> …<, x15>);
The EXPANDGRID function is part of the IMLMLIB library . The arguments to the EXPANDGRID function are k vectors, . The EXPANDGRID function returns a matrix that contains the Cartesian product of elements from the specified vectors. If the ith argument has elements, the return matrix has 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
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 on a grid of points in the region :
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;