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:ns5="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="ru">
7 <refname>ndgrid</refname>
9 <refpurpose>строит матриц или N-мерные массивы путем репликации данных векторов
17 <title>Последовательность вызова</title>
23 [X, Y, Z] = ndgrid(x,y,z)
25 [X, Y, Z, T] = ndgrid(x,y,z,t)
27 [X1, X2, ..., Xm] = ndgrid(x1,x2,...,xm)
33 <refsection role="arguments">
35 <title>Аргументы</title>
41 <term>x, y, z, ...</term>
45 <para>векторы любых типов данных. Они могут иметь различные типы данных.</para>
53 <term>X, Y, Z, ...</term>
57 <para>Matrices in case of 2 input arguments, or hypermatrices otherwise.
59 They all have the same sizes: size(x,"*") rows, size(y,"*") columns,
61 size(z,"*") layers, etc.
65 They have the datatypes of respective input vectors:
67 <literal>typeof(X)==typeof(x)</literal>,
69 <literal>typeof(Y)==typeof(y)</literal>, etc.
81 <refsection role="description">
83 <title>Описание</title>
86 The first application of <function>ndgrid</function> is to build
88 a grid of nodes meshing the 2D or 3D or N-D space according to 2, 3,
92 <literal>x</literal>, <literal> y</literal>, etc.. of
94 "template" coordinates sampled along each direction/dimension of the
96 space that you want to mesh.
101 Hence, the matrix or hypermatrix <literal>X</literal> is made
103 by replicating the vector <literal>x</literal> as all its columns;
105 the matrix or hypermatrix <literal>Y</literal> is made
107 by replicating the vector <literal>y</literal> as all its rows;
109 <literal>Z</literal> is made of replicating the vector
111 <literal>z</literal> along all its local thicknesses (3rd dimension);
119 <![CDATA[--> [X, Y] = ndgrid([1 3 4], [0 2 4 6])
134 This replication scheme can be generalized to any number of dimensions,
136 as well to any type of uniform data. Let's for instance consider 2
142 <listitem>The first is a number, to be chosen from the vector say
144 <literal>n = [ 3 7 ]</literal>
148 <listitem>The second is a letter, to be chosen from the vector
150 say <literal>c = ["a" "e" "i" "o" "u" "y"]</literal>
156 Then we want to build the set of all {n,c} possible pairs. It will
164 <![CDATA[--> [N, C] = ndgrid([3 7],["a" "e" "i" "o" "u" "y"])
175 <para>Then, the object(i,j) will have the properties
177 <literal>{n(i) c(j)}</literal> that now can be addressed with
179 <literal>{N(i,j) C(i,j)}</literal>.
181 This kind of grid may be useful to initialize an array of structures.
186 Following examples show how to use <varname>X, Y, Z</varname> in
188 most frequent applications.
195 <refsection role="examples">
197 <title>Примеры</title>
202 <emphasis role="bold">Example #1:</emphasis>
205 <programlisting role="example"><![CDATA[
206 // создание простой двухмерной координатной сетки
207 x = linspace(-10,2,40);
208 y = linspace(-5,5,40);
211 // Compute ordinates Z(X,Y) on the {X, Y} grid and plot Z(X,Y)
212 Z = X - 3*X.*sin(X).*cos(Y-4) ;
214 plot3d(x,y,Z, flag=[color("green") 2 4], alpha=7, theta=60); show_window()
215 ]]> </programlisting>
219 x = linspace(-10,2,40);
221 y = linspace(-5,5,40);
225 Z = X - 3*X.*sin(X).*cos(Y-4) ;
229 plot3d(x,y,Z, flag=[color("green") 2 4], alpha=7, theta=60); show_window()
236 <emphasis role="bold">Example #2:</emphasis>
239 <programlisting role="example"><![CDATA[
240 // создание простой трёхмерной координатной сетки
241 nx = 10; ny = 6; nz = 4;
242 x = linspace(0,2,nx);
243 y = linspace(0,1,ny);
244 z = linspace(0,0.5,nz);
245 [X,Y,Z] = ndgrid(x,y,z);
247 // попытаемся отобразить эту трёхмерную координатную сетку ...
251 [xf,yf,zf] = nf3d(X(:,:,k), Y(:,:,k), Z(:,:,k));
252 XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
256 [xf,yf,zf] = nf3d(matrix(X(:,j,:),[nx,nz]),..
257 matrix(Y(:,j,:),[nx,nz]),..
258 matrix(Z(:,j,:),[nx,nz]));
259 XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
263 plot3d(XF,YF,ZF, flag=[0 6 3], 66, 61, leg="X@Y@Z")
264 xtitle("Трёхмерная сетка!"); show_window()
267 <scilab:image localized="true">
269 nx = 10; ny = 6; nz = 4;
271 x = linspace(0,2,nx);
273 y = linspace(0,1,ny);
275 z = linspace(0,0.5,nz);
277 [X,Y,Z] = ndgrid(x,y,z);
287 [xf,yf,zf] = nf3d(X(:,:,k), Y(:,:,k), Z(:,:,k));
289 XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
297 [xf,yf,zf] = nf3d(matrix(X(:,j,:),[nx,nz]),..
299 matrix(Y(:,j,:),[nx,nz]),..
301 matrix(Z(:,j,:),[nx,nz]));
303 XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
311 plot3d(XF,YF,ZF, flag=[0 6 3], 66, 61, leg="X@Y@Z")
313 xtitle("Трёхмерная сетка!"); show_window()
322 <emphasis role="bold">Example #3: Create a table of digrams:</emphasis>
325 <programlisting role="example"><![CDATA[
326 [c1, c2] = ndgrid(["a" "b" "c"], ["a" "b" "c" "d" "e" "f" "g" "h"])
328 ]]> </programlisting>
332 <![CDATA[--> [c1, c2] = ndgrid(["a" "b" "c"], ["a" "b" "c" "d" "e" "f" "g" "h"])
345 !aa ab ac ad ae af ag ah !
346 !ba bb bc bd be bf bg bh !
347 !ca cb cc cd ce cf cg ch !
355 <refsection role="see also">
357 <title>Смотрите также</title>
359 <simplelist type="inline">
363 <link linkend="meshgrid">meshgrid</link>
369 <link linkend="kron">kron</link>
375 <link linkend="feval">feval</link>
381 <link linkend="eval3d">eval3d</link>
387 <link linkend="nf3d">nf3d</link>
395 <refsection role="history">
397 <title>История</title>
403 <revnumber>6.0</revnumber>
405 <revdescription>Extension to all homogeneous datatypes ([], booleans, encoded integers, polynomials, rationals, strings). Revision of the help page.