1 <?xml version="1.0" encoding="UTF-8"?>
3 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="ndgrid" xml:lang="pt">
7 <refname>ndgrid</refname>
9 <refpurpose>constrói matrizes ou matrizes N-D, replicando alguns vetores dadas
17 <title>Seqüência de Chamamento</title>
19 <synopsis>[X, Y] = ndgrid(x,y)
21 [X, Y, Z] = ndgrid(x,y,z)
23 [X, Y, Z, T] = ndgrid(x,y,z,t)
25 [X1, X2, ..., Xm] = ndgrid(x1,x2,...,xm)
31 <refsection role="arguments">
33 <title>Parâmetros</title>
39 <term>x, y, z, ...</term>
43 <para>vetores de quaisquer tipos de dados.
45 Eles podem ter tipos de dados distintos.
54 <term>X, Y, Z, ...</term>
58 <para>matrices in case of 2 input arguments, or hypermatrices otherwise.
60 They all have the same sizes: size(x,"*") rows, size(x,"*") columns,
62 size(z,"*") layers, etc.
64 They have the datatypes of respective input vectors:
66 <literal>typeof(X)==typeof(x)</literal>,
68 <literal>typeof(Y)==typeof(y)</literal>, etc.
80 <refsection role="description">
82 <title>Descrição</title>
85 The first application of <function>ndgrid</function> is to build
87 a grid of nodes meshing the 2D or 3D or N-D space according to 2, 3,
91 <literal>x</literal>, <literal> y</literal>, etc.. of
93 "template" coordinates sampled along each direction/dimension of the
95 space that you want to mesh.
100 Hence, the matrix or hypermatrix <literal>X</literal> is made
102 by replicating the vector <literal>x</literal> as all its columns;
104 the matrix or hypermatrix <literal>Y</literal> is made
106 by replicating the vector <literal>y</literal> as all its rows;
108 <literal>Z</literal> is made of replicating the vector
110 <literal>z</literal> along all its local thicknesses (3rd dimension);
118 <![CDATA[--> [X, Y] = ndgrid([1 3 4], [0 2 4 6])
133 Then, the coordinates of the node(i,j) in the 2D space
137 simply <literal>[x(i), y(j)]</literal> equal to
139 <literal>[X(i,j), Y(i,j)]</literal>. As well, the coordinates of a
141 <literal>node(i,j,k)</literal> of a 3D grid will be
143 <literal>[x(i), y(j), z(k)]</literal> equal to
145 <literal>[X(i,j,k), Y(i,j,k), Z(i,j,k)]</literal>.
151 This replication scheme can be generalized to any number of dimensions,
153 as well to any type of uniform data. Let's for instance consider 2
159 <listitem>The first is a number, to be chosen from the vector say
161 <literal>n = [ 3 7 ]</literal>
165 <listitem>The second is a letter, to be chosen from the vector
167 say <literal>c = ["a" "e" "i" "o" "u" "y"]</literal>
173 Then we want to build the set of all {n,c} possible pairs. It will
181 <![CDATA[--> [N, C] = ndgrid([3 7],["a" "e" "i" "o" "u" "y"])
192 <para>Then, the object(i,j) will have the properties
194 <literal>{n(i) c(j)}</literal> that now can be addressed with
196 <literal>{N(i,j) C(i,j)}</literal>.
198 This kind of grid may be useful to initialize an array of structures.
203 Following examples show how to use <varname>X, Y, Z</varname> in
205 most frequent applications.
212 <refsection role="examples">
214 <title>Exemplos </title>
219 <emphasis role="bold">Example #1:</emphasis>
222 <programlisting role="example"><![CDATA[
223 // Criando um grid 2d simples
224 x = linspace(-10,2,40);
225 y = linspace(-5,5,40);
228 // Compute ordinates Z(X,Y) on the {X, Y} grid and plot Z(X,Y)
229 Z = X - 3*X.*sin(X).*cos(Y-4) ;
231 plot3d(x,y,Z, flag=[color("green") 2 4], alpha=7, theta=60); show_window()
236 x = linspace(-10,2,40);
238 y = linspace(-5,5,40);
242 Z = X - 3*X.*sin(X).*cos(Y-4) ;
246 plot3d(x,y,Z, flag=[color("green") 2 4], alpha=7, theta=60); show_window()
253 <emphasis role="bold">Example #2:</emphasis>
256 <programlisting role="example"><![CDATA[
257 // criando um grid 3d simples
258 nx = 10; ny = 6; nz = 4;
259 x = linspace(0,2,nx);
260 y = linspace(0,1,ny);
261 z = linspace(0,0.5,nz);
262 [X,Y,Z] = ndgrid(x,y,z);
263 // tente exibir este grid 3d...
266 [xf,yf,zf] = nf3d(X(:,:,k),Y(:,:,k),Z(:,:,k));
267 XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
270 [xf,yf,zf] = nf3d(matrix(X(:,j,:),[nx,nz]),...
271 matrix(Y(:,j,:),[nx,nz]),...
272 matrix(Z(:,j,:),[nx,nz]));
273 XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
276 plot3d(XF,YF,ZF, flag=[0 6 3], 66, 61, leg="X@Y@Z")
277 xtitle("A 3d grid !"); show_window()
278 ]]> </programlisting>
282 nx = 10; ny = 6; nz = 4;
284 x = linspace(0,2,nx);
286 y = linspace(0,1,ny);
288 z = linspace(0,0.5,nz);
290 [X,Y,Z] = ndgrid(x,y,z);
300 [xf,yf,zf] = nf3d(X(:,:,k),Y(:,:,k),Z(:,:,k));
302 XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
310 [xf,yf,zf] = nf3d(matrix(X(:,j,:),[nx,nz]),...
312 matrix(Y(:,j,:),[nx,nz]),...
314 matrix(Z(:,j,:),[nx,nz]));
316 XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
320 plot3d(XF,YF,ZF, flag=[0 6 3], 66, 61, leg="X@Y@Z")
322 xtitle("A 3d grid !");
329 <emphasis role="bold">Example #3: Create a table of digrams:</emphasis>
332 <programlisting role="example"><![CDATA[
333 [c1, c2] = ndgrid(["a" "b" "c"], ["a" "b" "c" "d" "e" "f" "g" "h"])
335 ]]> </programlisting>
339 <![CDATA[--> [c1, c2] = ndgrid(["a" "b" "c"], ["a" "b" "c" "d" "e" "f" "g" "h"])
352 !aa ab ac ad ae af ag ah !
353 !ba bb bc bd be bf bg bh !
354 !ca cb cc cd ce cf cg ch !
362 <refsection role="see also">
364 <title>Ver Também</title>
366 <simplelist type="inline">
370 <link linkend="meshgrid">meshgrid</link>
376 <link linkend="kron">kron</link>
382 <link linkend="feval">feval</link>
388 <link linkend="eval3d">eval3d</link>
394 <link linkend="nf3d">nf3d</link>
402 <refsection role="history">
404 <title>Histórico</title>
410 <revnumber>6.0</revnumber>
412 <revdescription>Extension to all homogeneous datatypes ([], booleans, encoded integers,
413 polynomials, rationals, strings). Revision of the help page.