X-Git-Url: http://gitweb.scilab.org/?p=scilab.git;a=blobdiff_plain;f=scilab%2Fmodules%2Felementary_functions%2Fhelp%2Fen_US%2Felementarymatrices%2Fndgrid.xml;h=2e76816cc3110e7052b0eee4f28d067af4ba9bbc;hp=f79e766d0a655e15a733ff517c4193b22c547bb6;hb=29245cff60dfcf13e8e2d786ef4659c8252614b6;hpb=4919860751004f724e4d1d82f5fffaf3dedda0d2 diff --git a/scilab/modules/elementary_functions/help/en_US/elementarymatrices/ndgrid.xml b/scilab/modules/elementary_functions/help/en_US/elementarymatrices/ndgrid.xml index f79e766..2e76816 100644 --- a/scilab/modules/elementary_functions/help/en_US/elementarymatrices/ndgrid.xml +++ b/scilab/modules/elementary_functions/help/en_US/elementarymatrices/ndgrid.xml @@ -1,100 +1,126 @@ - - - \$LastChangedDate\$ - - - ndgrid - arrays for multidimensional function evaluation on - grid - - - Calling Sequence - [X, Y] = ndgrid(x,y) -[X, Y, Z] = ndgrid(x,y,z) -[X, Y, Z, T] = ndgrid(x,y,z,t) -[X1, X2, ..., Xm] = ndgrid(x1,x2,...,xm) - - - Arguments - - - x, y, z, ... - - vectors - - - - X, Y, Z, ... - - matrices in case of 2 input arguments, or else - hypermatrices - - - - - - Description - This is an utility routine useful to create arrays for function - evaluation on 2, 3, ..., n dimensional grids. For instance in 2d, a grid - is defined by two vectors, x and y - of length nx and ny, and you want to evaluate a function (says - f) on all the grid points, that is on all the points - of coordinates (x(i),y(j)) with - i=1,..,nx and j=1,..,ny. In this - case, this function can compute the two matrices X,Y of - size nx x ny such that : - - and the evaluation may be done with Z=f(X,Y) (at - the condition that you have coded f for evaluation on - vector arguments, which is done (in general) by using the element-wise - operators .*, ./ and - .^ in place of *, - / and ^). - In the 3d case, considering 3 vectors x,y,z of - length nx, ny and nz, X,Y,Z are 3 hypermatrices of size - nx x ny x nz such that : - - In the general case of m input arguments x1, x2, .., - xm, then the m output arguments X1, X2, .., - Xm are hypermatrices of size nx1 x nx2 x ... x - nxm and : - - - - Examples - + + ndgrid + build matrices or N-D arrays by replicating some template vectors + + + + + Calling Sequence + + [X, Y] = ndgrid(x,y) + [X, Y, Z] = ndgrid(x,y,z) + [X, Y, Z, T] = ndgrid(x,y,z,t) + [X1, X2, ..., Xm] = ndgrid(x1,x2,...,xm) + + + + Arguments + + + x, y, z, ... + + vectors of any data types. They may have distinct data types. + + + + X, Y, Z, ... + + + matrices in case of 2 input arguments, or hypermatrices otherwise. They all have the same sizes: `size(x,"*")` rows, `size(y,"*")` columns, `size(z,"*")` layers, etc. They have the datatypes of respective input vectors: typeof(X)==typeof(x), typeof(Y)==typeof(y), etc. + + + + + + + Description + + The first application of ndgrid is to build a grid of nodes meshing the 2D or 3D or N-D space according to 2, 3, or more sets x, y, etc.. of "template" coordinates sampled along each direction/dimension of the space that you want to mesh. + + + Hence, the matrix or hypermatrix X is made by replicating the vector x as all its columns ; the matrix or hypermatrix Y is made by replicating the vector y as all its rows ; Z is made of replicating the vector z along all its local thicknesses (3rd dimension); etc. + + [X, Y] = ndgrid([1 3 4], [0 2 4 6]) + X = + 1. 1. 1. 1. + 3. 3. 3. 3. + 4. 4. 4. 4. + + Y = + 0. 2. 4. 6. + 0. 2. 4. 6. + 0. 2. 4. 6. +]]> + + Then, the coordinates of the node(i,j) in the 2D space will be simply [x(i), y(j)] now given by [X(i,j), Y(i,j)]. As well, the coordinates of a node(i,j,k) of a 3D grid will be [x(i), y(j), z(k)] now given by [X(i,j,k), Y(i,j,k), Z(i,j,k)]. + + This replication scheme can be generalized to any number of dimensions, as well to any type of uniform data. Let's for instance consider 2 attributes: + + + The first is a number, to be chosen from the vector say n= [ 3 7 ] + + + The second is a letter, to be chosen from the vector say c= ["a" "e" "i" "o" "u" "y"] + + + Then we want to build the set of all {n,c} possible pairs. It will just be the 2D grid: + + [N, C] = ndgrid([3 7],["a" "e" "i" "o" "u" "y"]) + C = +!a e i o u y ! +!a e i o u y ! + + N = + 3. 3. 3. 3. 3. 3. + 7. 7. 7. 7. 7. 7. +]]> + + Then, the object(i,j) will have the properties {n(i) c(j)} that now can be addressed with {N(i,j) C(i,j)}. This kind of grid may be useful to initialize an array of structures. + + + Following examples show how to use X, Y, Z in most frequent applications. + + + + Examples + + Example #1: + + + + + Example #2: + + - - - See Also - - - kron - - - - - Authors - B. Pincon - + + + Example #3: Creates a table of digrams: + + + [c1, c2] = ndgrid(["a" "b" "c"], ["a" "b" "c" "d" "e" "f" "g" "h"]) + c2 = +!a b c d e f g h ! +!a b c d e f g h ! +!a b c d e f g h ! + + c1 = +!a a a a a a a a ! +!b b b b b b b b ! +!c c c c c c c c ! + +--> c1+c2 + ans = +!aa ab ac ad ae af ag ah ! +!ba bb bc bd be bf bg bh ! +!ca cb cc cd ce cf cg ch ! +]]> + + + See Also + + + meshgrid + + + kron + + + feval + + + eval3d + + + nf3d + + + + + History + + + 6.0 + Extension to all homogeneous datatypes ([], booleans, encoded integers, polynomials, rationals, strings). Revision of the help page. + + +