* Bug #8431: eval3d() set obsolete
[scilab.git] / scilab / modules / elementary_functions / help / ru_RU / elementarymatrices / ndgrid.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2
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">
4     
5     <refnamediv>
6         
7         <refname>ndgrid</refname>
8         
9         <refpurpose>строит матриц или N-мерные массивы путем репликации данных векторов
10             
11         </refpurpose>
12         
13     </refnamediv>
14     
15     <refsynopsisdiv>
16         
17         <title>Синтаксис</title>
18         
19         <synopsis>
20             
21             X, Y] = ndgrid(x,y)
22             
23             [X, Y, Z] = ndgrid(x,y,z)
24             
25             [X, Y, Z, T] = ndgrid(x,y,z,t)
26             
27             [X1, X2, ..., Xm] = ndgrid(x1,x2,...,xm)
28             
29         </synopsis>
30         
31     </refsynopsisdiv>
32     
33     <refsection role="arguments">
34         
35         <title>Аргументы</title>
36         
37         <variablelist>
38             
39             <varlistentry>
40                 
41                 <term>x, y, z, ...</term>
42                 
43                 <listitem>
44                     
45                     <para>векторы любых типов данных. Они могут иметь различные типы данных.</para>
46                     
47                 </listitem>
48                 
49             </varlistentry>
50             
51             <varlistentry>
52                 
53                 <term>X, Y, Z, ...</term>
54                 
55                 <listitem>
56                     
57                     <para>Matrices in case of 2 input arguments, or hypermatrices otherwise.
58                         
59                         They all have the same sizes: size(x,"*") rows, size(y,"*") columns, 
60                         
61                         size(z,"*") layers, etc.
62                     </para>
63                     <para>
64                         
65                         They have the datatypes of respective input vectors:
66                         
67                         <literal>typeof(X)==typeof(x)</literal>, 
68                         
69                         <literal>typeof(Y)==typeof(y)</literal>, etc.
70                         
71                     </para>
72                     
73                 </listitem>
74                 
75             </varlistentry>
76             
77         </variablelist>
78         
79     </refsection>
80     
81     <refsection role="description">
82         
83         <title>Описание</title>
84         
85         <para>
86             The first application of <function>ndgrid</function> is to build
87             
88             a grid of nodes meshing the 2D or 3D or N-D space according to 2, 3,
89             
90             or more sets
91             
92             <literal>x</literal>, <literal> y</literal>, etc.. of  
93             
94             "template" coordinates sampled along each direction/dimension of the
95             
96             space that you want to mesh.
97             
98         </para>
99         
100         <para>
101             Hence, the matrix or hypermatrix <literal>X</literal> is made
102             
103             by replicating the vector <literal>x</literal> as all its columns; 
104             
105             the matrix or hypermatrix <literal>Y</literal> is made
106             
107             by replicating the vector <literal>y</literal> as all its rows;
108             
109             <literal>Z</literal> is made of replicating the vector 
110             
111             <literal>z</literal> along all its local thicknesses (3rd dimension); 
112             
113             etc
114             
115         </para>
116         
117         <screen>
118             
119             <![CDATA[--> [X, Y] = ndgrid([1 3 4], [0 2 4 6])
120  X  = 
121    1.   1.   1.   1.
122    3.   3.   3.   3.
123    4.   4.   4.   4.
124
125    Y  = 
126    0.   2.   4.   6.
127    0.   2.   4.   6.
128    0.   2.   4.   6.
129 ]]>
130         </screen>
131         
132         <para>
133             
134             This replication scheme can be generalized to any number of dimensions,
135             
136             as well to any type of uniform data. Let's for instance consider 2
137             
138             attributes:
139             
140             <orderedlist>
141                 
142                 <listitem>The first is a number, to be chosen from the vector say
143                     
144                     <literal>n = [ 3 7 ]</literal>
145                     
146                 </listitem>
147                 
148                 <listitem>The second is a letter, to be chosen from the vector 
149                     
150                     say <literal>c = ["a" "e" "i" "o" "u" "y"]</literal>
151                     
152                 </listitem>
153                 
154             </orderedlist>
155             
156             Then we want to build the set of all {n,c} possible pairs. It will
157             
158             just be the 2D grid:
159             
160         </para>
161         
162         <screen>
163             
164             <![CDATA[--> [N, C] = ndgrid([3 7],["a" "e" "i" "o" "u" "y"])
165  C  = 
166 !a  e  i  o  u  y  !
167 !a  e  i  o  u  y  !
168
169  N  = 
170    3.   3.   3.   3.   3.   3.
171    7.   7.   7.   7.   7.   7.
172 ]]>
173         </screen>
174         
175         <para>Then, the object(i,j) will have the properties 
176             
177             <literal>{n(i) c(j)}</literal> that now can be addressed with
178             
179             <literal>{N(i,j) C(i,j)}</literal>.
180             
181             This kind of grid may be useful to initialize an array of structures.
182             
183         </para>
184         
185         <para>
186             Following examples show how to use <varname>X, Y, Z</varname> in
187             
188             most frequent applications.
189             
190         </para>
191         
192         
193     </refsection>
194     
195     <refsection role="examples">
196         
197         <title>Примеры</title>
198         
199         
200         
201         <para>
202             <emphasis role="bold">Example #1:</emphasis> 
203         </para>
204         
205         <programlisting role="example"><![CDATA[  
206 // создание простой двухмерной координатной сетки
207 x = linspace(-10,2,40);
208 y = linspace(-5,5,40);
209 [X,Y] = ndgrid(x,y);
210
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) ;
213 clf()
214 plot3d(x,y,Z, flag=[color("green") 2 4], alpha=7, theta=60); show_window()
215  ]]>    </programlisting>
216         
217         <scilab:image>
218             
219             x = linspace(-10,2,40);
220             
221             y = linspace(-5,5,40);
222             
223             [X,Y] = ndgrid(x,y);
224             
225             Z = X - 3*X.*sin(X).*cos(Y-4) ;
226             
227             clf()
228             
229             plot3d(x,y,Z, flag=[color("green") 2 4], alpha=7, theta=60); show_window()
230             
231         </scilab:image>
232         
233         
234         
235         <para>
236             <emphasis role="bold">Example #2:</emphasis> 
237         </para>
238         
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);
246  
247 // попытаемся отобразить эту трёхмерную координатную сетку ...
248 XF=[]; YF=[]; ZF=[];
249  
250 for k=1:nz
251    [xf,yf,zf] = nf3d(X(:,:,k), Y(:,:,k), Z(:,:,k));
252    XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
253 end
254  
255 for j=1:ny
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];
260 end
261  
262 clf()
263 plot3d(XF,YF,ZF, flag=[0 6 3], 66, 61, leg="X@Y@Z")
264 xtitle("Трёхмерная сетка!"); show_window()
265  ]]></programlisting>
266         
267         <scilab:image localized="true">
268             
269             nx = 10; ny = 6; nz = 4;
270             
271             x = linspace(0,2,nx);
272             
273             y = linspace(0,1,ny);
274             
275             z = linspace(0,0.5,nz);
276             
277             [X,Y,Z] = ndgrid(x,y,z);
278             
279             
280             
281             XF=[]; YF=[]; ZF=[];
282             
283             
284             
285             for k=1:nz
286             
287             [xf,yf,zf] = nf3d(X(:,:,k), Y(:,:,k), Z(:,:,k));
288             
289             XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
290             
291             end
292             
293             
294             
295             for j=1:ny
296             
297             [xf,yf,zf] = nf3d(matrix(X(:,j,:),[nx,nz]),..
298             
299             matrix(Y(:,j,:),[nx,nz]),..
300             
301             matrix(Z(:,j,:),[nx,nz]));
302             
303             XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
304             
305             end
306             
307             
308             
309             clf()
310             
311             plot3d(XF,YF,ZF, flag=[0 6 3], 66, 61, leg="X@Y@Z")
312             
313             xtitle("Трёхмерная сетка!"); show_window()
314             
315             
316             
317         </scilab:image>
318         
319         
320         
321         <para>
322             <emphasis role="bold">Example #3: Create a table of digrams:</emphasis> 
323         </para>
324         
325         <programlisting role="example"><![CDATA[  
326 [c1, c2] = ndgrid(["a" "b" "c"], ["a" "b" "c" "d" "e" "f" "g" "h"])
327 c1+c2
328  ]]>    </programlisting>
329         
330         <screen>
331             
332             <![CDATA[--> [c1, c2] = ndgrid(["a" "b" "c"], ["a" "b" "c" "d" "e" "f" "g" "h"])
333  c2  = 
334 !a  b  c  d  e  f  g  h  !
335 !a  b  c  d  e  f  g  h  !
336 !a  b  c  d  e  f  g  h  !
337
338  c1  = 
339 !a  a  a  a  a  a  a  a  !
340 !b  b  b  b  b  b  b  b  !
341 !c  c  c  c  c  c  c  c  !
342
343 --> c1+c2
344  ans  =
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  !
348 ]]>
349         </screen>
350         
351         
352         
353     </refsection>
354     
355     <refsection role="see also">
356         
357         <title>Смотрите также</title>
358         
359         <simplelist type="inline">
360             
361             <member>
362                 
363                 <link linkend="meshgrid">meshgrid</link>
364                 
365             </member>
366             
367             <member>
368                 
369                 <link linkend="kron">kron</link>
370                 
371             </member>
372             
373             <member>
374                 
375                 <link linkend="feval">feval</link>
376                 
377             </member>
378             
379             <member>
380                 
381                 <link linkend="nf3d">nf3d</link>
382                 
383             </member>
384             
385         </simplelist>
386         
387     </refsection>
388     
389     <refsection role="history">
390         
391         <title>История</title>
392         
393         <revhistory>
394             
395             <revision>
396                 
397                 <revnumber>6.0</revnumber>
398                 
399                 <revdescription>Extension to all homogeneous datatypes ([], booleans, encoded integers, polynomials, rationals, strings). Revision of the help page.
400                     
401                 </revdescription>
402                 
403             </revision>
404             
405         </revhistory>
406         
407     </refsection>
408     
409 </refentry>
410