1 <?xml version="1.0" encoding="UTF-8"?>
\r
2 <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">
\r
4 <refname>ndgrid</refname>
\r
5 <refpurpose>constrói matrizes ou matrizes N-D, replicando alguns vetores dadas
\r
9 <title>Seqüência de Chamamento</title>
\r
10 <synopsis>[X, Y] = ndgrid(x,y)
\r
11 [X, Y, Z] = ndgrid(x,y,z)
\r
12 [X, Y, Z, T] = ndgrid(x,y,z,t)
\r
13 [X1, X2, ..., Xm] = ndgrid(x1,x2,...,xm)
\r
16 <refsection role="arguments">
\r
17 <title>Parâmetros</title>
\r
20 <term>x, y, z, ...</term>
\r
22 <para>vetores de quaisquer tipos de dados.
\r
23 Eles podem ter tipos de dados distintos.</para>
\r
27 <term>X, Y, Z, ...</term>
\r
29 <para>matrizes, no caso de 2 argumentos de entrada, ou hipermatrizes
\r
36 <refsection role="description">
\r
37 <title>Descrição</title>
\r
38 <para>The first application of <function>ndgrid</function> is to build
\r
39 a grid of nodes meshing the 2D or 3D or N-D space according to 2, 3,
\r
41 <literal>x</literal>, <literal> y</literal>, etc.. of
\r
42 "template" coordinates sampled along each direction/dimension of the
\r
43 space that you want to mesh.
\r
45 <para>Hence, the matrix or hypermatrix <literal>X</literal> is made
\r
46 by replicating the vector <literal>x</literal> as all its columns ;
\r
47 the matrix or hypermatrix <literal>Y</literal> is made
\r
48 by replicating the vector <literal>y</literal> as all its rows ;
\r
49 <literal>Z</literal> is made of replicating the vector
\r
50 <literal>z</literal> along all its local thicknesses (3rd dimension);
\r
54 <![CDATA[--> [X, Y] = ndgrid([1 3 4], [0 2 4 6])
\r
66 Then, the coordinates of the node(i,j) in the 2D space
\r
68 simply <literal>[x(i), y(j)]</literal> equal to
\r
69 <literal>[X(i,j), Y(i,j)]</literal>. As well, the coordinates of a
\r
70 <literal>node(i,j,k)</literal> of a 3D grid will be
\r
71 <literal>[x(i), y(j), z(k)]</literal> equal to
\r
72 <literal>[X(i,j,k), Y(i,j,k), Z(i,j,k)]</literal>.
\r
75 This replication scheme can be generalized to any number of dimensions,
\r
76 as well to any type of uniform data. Let's for instance consider 2
\r
79 <listitem>The first is a number, to be chosen from the vector say
\r
80 <literal>n = [ 3 7 ]</literal>
\r
82 <listitem>The second is a letter, to be chosen from the vector
\r
83 say <literal>c = ["a" "e" "i" "o" "u" "y"]</literal>
\r
86 Then we want to build the set of all {n,c} possible pairs. It will
\r
87 just be the 2D grid:
\r
90 <![CDATA[--> [N, C] = ndgrid([3 7],["a" "e" "i" "o" "u" "y"])
\r
99 <para>Then, the object(i,j) will have the properties
\r
100 <literal>{n(i) c(j)}</literal> that now can be addressed with
\r
101 <literal>{N(i,j) C(i,j)}</literal>.
\r
102 This kind of grid may be useful to initialize an array of structures.
\r
104 <para>Following examples show how to use <varname>X, Y, Z</varname> in
\r
105 most frequent applications.
\r
108 <refsection role="examples">
\r
109 <title>Exemplos </title>
\r
111 <para><emphasis role="bold">Example #1:</emphasis> </para>
\r
112 <programlisting role="example"><![CDATA[
\r
113 // Criando um grid 2d simples
\r
114 x = linspace(-10,2,40);
\r
115 y = linspace(-5,5,40);
\r
116 [X,Y] = ndgrid(x,y);
\r
118 // Compute ordinates Z(X,Y) on the {X, Y} grid and plot Z(X,Y)
\r
119 Z = X - 3*X.*sin(X).*cos(Y-4) ;
\r
121 plot3d(x,y,Z, flag=[color("green") 2 4], alpha=7, theta=60); show_window()
\r
122 ]]></programlisting>
\r
124 x = linspace(-10,2,40);
\r
125 y = linspace(-5,5,40);
\r
126 [X,Y] = ndgrid(x,y);
\r
127 Z = X - 3*X.*sin(X).*cos(Y-4) ;
\r
129 plot3d(x,y,Z, flag=[color("green") 2 4], alpha=7, theta=60); show_window()
\r
132 <para><emphasis role="bold">Example #2:</emphasis> </para>
\r
133 <programlisting role="example"><![CDATA[
\r
134 // criando um grid 3d simples
\r
135 nx = 10; ny = 6; nz = 4;
\r
136 x = linspace(0,2,nx);
\r
137 y = linspace(0,1,ny);
\r
138 z = linspace(0,0.5,nz);
\r
139 [X,Y,Z] = ndgrid(x,y,z);
\r
140 // tente exibir este grid 3d...
\r
141 XF=[]; YF=[]; ZF=[];
\r
143 [xf,yf,zf] = nf3d(X(:,:,k),Y(:,:,k),Z(:,:,k));
\r
144 XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
\r
147 [xf,yf,zf] = nf3d(matrix(X(:,j,:),[nx,nz]),...
\r
148 matrix(Y(:,j,:),[nx,nz]),...
\r
149 matrix(Z(:,j,:),[nx,nz]));
\r
150 XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
\r
153 plot3d(XF,YF,ZF, flag=[0 6 3], 66, 61, leg="X@Y@Z")
\r
154 xtitle("A 3d grid !"); show_window()
\r
155 ]]> </programlisting>
\r
157 nx = 10; ny = 6; nz = 4;
\r
158 x = linspace(0,2,nx);
\r
159 y = linspace(0,1,ny);
\r
160 z = linspace(0,0.5,nz);
\r
161 [X,Y,Z] = ndgrid(x,y,z);
\r
163 XF=[]; YF=[]; ZF=[];
\r
166 [xf,yf,zf] = nf3d(X(:,:,k),Y(:,:,k),Z(:,:,k));
\r
167 XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
\r
171 [xf,yf,zf] = nf3d(matrix(X(:,j,:),[nx,nz]),...
\r
172 matrix(Y(:,j,:),[nx,nz]),...
\r
173 matrix(Z(:,j,:),[nx,nz]));
\r
174 XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
\r
176 plot3d(XF,YF,ZF, flag=[0 6 3], 66, 61, leg="X@Y@Z")
\r
177 xtitle("A 3d grid !");
\r
180 <para><emphasis role="bold">Example #3: Create a table of digrams:</emphasis> </para>
\r
181 <programlisting role="example"><![CDATA[
\r
182 [c1, c2] = ndgrid(["a" "b" "c"], ["a" "b" "c" "d" "e" "f" "g" "h"])
\r
184 ]]> </programlisting>
\r
186 <![CDATA[--> [c1, c2] = ndgrid(["a" "b" "c"], ["a" "b" "c" "d" "e" "f" "g" "h"])
\r
199 !aa ab ac ad ae af ag ah !
\r
200 !ba bb bc bd be bf bg bh !
\r
201 !ca cb cc cd ce cf cg ch !
\r
205 <refsection role="see also">
\r
206 <title>Ver Também</title>
\r
207 <simplelist type="inline">
\r
209 <link linkend="meshgrid">meshgrid</link>
\r
212 <link linkend="kron">kron</link>
\r
215 <link linkend="feval">feval</link>
\r
218 <link linkend="eval3d">eval3d</link>
\r
221 <link linkend="nf3d">nf3d</link>
\r
225 <refsection role="history">
\r
226 <title>Histórico</title>
\r
229 <revnumber>6.0</revnumber>
\r
230 <revdescription>Extension to all homogeneous datatypes ([], booleans, encoded integers, polynomials, rationals, strings). Revision of the help page.
\r