The EXPANDGRID function is part of the IMLMLIB library. The arguments to the EXPANDGRID function are vectors, . The EXPANDGRID function returns a matrix that contains the Cartesian product of elements from the specified vectors. If the th argument has elements, the return matrix has rows and 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 24.125: 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 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;