<?xml version="1.0" encoding="UTF-8"?>
+
<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="en">
+
<refnamediv>
+
<refname>ndgrid</refname>
- <refpurpose>arrays for multidimensional function evaluation on
- grid
+
+ <refpurpose>build matrices or N-D arrays by replicating some template vectors
+
</refpurpose>
+
</refnamediv>
+
<refsynopsisdiv>
+
<title>Calling Sequence</title>
+
<synopsis>[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)
+
</synopsis>
+
</refsynopsisdiv>
- <refsection>
+
+ <refsection role="arguments">
+
<title>Arguments</title>
+
<variablelist>
+
<varlistentry>
+
<term>x, y, z, ...</term>
+
<listitem>
- <para>vectors</para>
+
+ <para>vectors of any data types. They may have distinct data types.</para>
+
</listitem>
+
</varlistentry>
+
<varlistentry>
+
<term>X, Y, Z, ...</term>
+
<listitem>
- <para>matrices in case of 2 input arguments, or else
- hypermatrices
+
+ <para>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:
+
+ <literal>typeof(X)==typeof(x)</literal>,
+
+ <literal>typeof(Y)==typeof(y)</literal>, etc.
+
</para>
+
</listitem>
+
</varlistentry>
+
</variablelist>
+
</refsection>
- <refsection>
+
+ <refsection role="description">
+
<title>Description</title>
- <para>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, <literal>x</literal> and <literal> y</literal>
- of length nx and ny, and you want to evaluate a function (says
- <emphasis>f</emphasis>) on all the grid points, that is on all the points
- of coordinates <emphasis>(x(i),y(j))</emphasis> with
- <emphasis>i=1,..,nx</emphasis> and <emphasis>j=1,..,ny</emphasis>. In this
- case, this function can compute the two matrices <literal>X,Y</literal> of
- size <emphasis>nx x ny</emphasis> such that :
+
+ <para>
+ The first application of <function>ndgrid</function> is to build
+
+ a grid of nodes meshing the 2D or 3D or N-D space according to 2, 3,
+
+ or more sets
+
+ <literal>x</literal>, <literal> y</literal>, etc.. of
+
+ "template" coordinates sampled along each direction/dimension of the
+
+ space that you want to mesh.
+
</para>
- <programlisting role="no-scilab-exec"><![CDATA[
-X(i,j) = x(i) for all i in [1,nx]
-Y(i,j) = y(j) and j in [1,ny]
- ]]></programlisting>
+
<para>
- and the evaluation may be done with <literal>Z=f(X,Y)</literal> (at
- the condition that you have coded <literal>f</literal> for evaluation on
- vector arguments, which is done (in general) by using the element-wise
- operators <literal>.*</literal>, <literal>./</literal> and
- <literal>.^</literal> in place of <literal>*</literal>,
- <literal>/</literal> and <literal>^</literal>).
+ Hence, the matrix or hypermatrix <literal>X</literal> is made
+
+ by replicating the vector <literal>x</literal> as all its columns ;
+
+ the matrix or hypermatrix <literal>Y</literal> is made
+
+ by replicating the vector <literal>y</literal> as all its rows ;
+
+ <literal>Z</literal> is made of replicating the vector
+
+ <literal>z</literal> along all its local thicknesses (3rd dimension);
+
+ etc
+
</para>
+
+ <screen>
+
+ <![CDATA[--> [X, Y] = ndgrid([1 3 4], [0 2 4 6])\r
+ X = \r
+ 1. 1. 1. 1.\r
+ 3. 3. 3. 3.\r
+ 4. 4. 4. 4.\r
+\r
+ Y = \r
+ 0. 2. 4. 6.\r
+ 0. 2. 4. 6.\r
+ 0. 2. 4. 6.\r
+]]>
+ </screen>
+
+ <para>
+
+ Then, the coordinates of the node(i,j) in the 2D space
+
+ will be
+
+ simply <literal>[x(i), y(j)]</literal> now given by
+
+ <literal>[X(i,j), Y(i,j)]</literal>. As well, the coordinates of a
+
+ <literal>node(i,j,k)</literal> of a 3D grid will be
+
+ <literal>[x(i), y(j), z(k)]</literal> now given by
+
+ <literal>[X(i,j,k), Y(i,j,k), Z(i,j,k)]</literal>.
+
+ </para>
+
<para>
- In the 3d case, considering 3 vectors <literal>x,y,z</literal> of
- length nx, ny and nz, <literal>X,Y,Z</literal> are 3 hypermatrices of size
- <emphasis>nx x ny x nz</emphasis> such that :
+
+ 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:
+
+ <orderedlist>
+
+ <listitem>The first is a number, to be chosen from the vector say
+
+ <literal>n = [ 3 7 ]</literal>
+
+ </listitem>
+
+ <listitem>The second is a letter, to be chosen from the vector
+
+ say <literal>c = ["a" "e" "i" "o" "u" "y"]</literal>
+
+ </listitem>
+
+ </orderedlist>
+
+ Then we want to build the set of all {n,c} possible pairs. It will
+
+ just be the 2D grid:
+
</para>
- <programlisting role="no-scilab-exec"><![CDATA[
-X(i,j,k) = x(i)
-Y(i,j,k) = y(j) for all (i,j,k) in [1,nx]x[1,ny]x[1,nz]
-Z(i,j,k) = z(k)
- ]]></programlisting>
+
+ <screen>
+
+ <![CDATA[--> [N, C] = ndgrid([3 7],["a" "e" "i" "o" "u" "y"])\r
+ C = \r
+!a e i o u y !\r
+!a e i o u y !\r
+\r
+ N = \r
+ 3. 3. 3. 3. 3. 3.\r
+ 7. 7. 7. 7. 7. 7.\r
+]]>
+ </screen>
+
+ <para>Then, the object(i,j) will have the properties
+
+ <literal>{n(i) c(j)}</literal> that now can be addressed with
+
+ <literal>{N(i,j) C(i,j)}</literal>.
+
+ This kind of grid may be useful to initialize an array of structures.
+
+ </para>
+
<para>
- In the general case of m input arguments <literal>x1, x2, ..,
- xm
- </literal>
- ,then the m output arguments <literal>X1, X2, ..,
- Xm
- </literal>
- are hypermatrices of size <emphasis>nx1 x nx2 x ... x
- nxm
- </emphasis>
- and :
+ Following examples show how to use <varname>X, Y, Z</varname> in
+
+ most frequent applications.
+
</para>
- <programlisting role="no-scilab-exec"><![CDATA[
-Xj(i1,i2,...,ij,...,im) = xj(ij)
-for all (i1,i2,...,im) in [1,nx1]x[1,nx2]x...x[1,nxm]
- ]]></programlisting>
+
+
</refsection>
- <refsection>
+
+ <refsection role="examples">
+
<title>Examples</title>
- <programlisting role="example"><![CDATA[
-// create a simple 2d grid
-nx = 40; ny = 40;
-x = linspace(-1,1,nx);
-y = linspace(-1,1,ny);
-[X,Y] = ndgrid(x,y);
-
-// compute a function on the grid and plot it
-//deff("z=f(x,y)","z=128*x.^2 .*(1-x).^2 .*y.^2 .*(1-y).^2");
-deff("z=f(x,y)","z=x.^2 + y.^3")
-Z = f(X,Y);
-clf()
-plot3d(x,y,Z, flag=[2 6 4]); show_window()
+
+ <para>
+ <emphasis role="bold">Example #1:</emphasis>
+ </para>
+
+ <programlisting role="example"><![CDATA[ \r
+// Create a simple 2d grid\r
+x = linspace(-10,2,40);\r
+y = linspace(-5,5,40);\r
+[X,Y] = ndgrid(x,y);\r
+\r
+// Compute ordinates Z(X,Y) on the {X, Y} grid and plot Z(X,Y)\r
+Z = X - 3*X.*sin(X).*cos(Y-4) ;\r
+clf()\r
+plot3d(x,y,Z, flag=[color("green") 2 4], alpha=7, theta=60); show_window()\r
]]></programlisting>
+
<scilab:image>
- nx = 40; ny = 40;
- x = linspace(-1,1,nx);
- y = linspace(-1,1,ny);
+
+ x = linspace(-10,2,40);
+
+ y = linspace(-5,5,40);
+
[X,Y] = ndgrid(x,y);
- deff("z=f(x,y)","z=x.^2 + y.^3")
- Z = f(X,Y);
- plot3d(x,y,Z, flag=[2 6 4]);
+
+ Z = X - 3*X.*sin(X).*cos(Y-4) ;
+
+ clf()
+
+ plot3d(x,y,Z, flag=[color("green") 2 4], alpha=7, theta=60); show_window()
+
</scilab:image>
- <programlisting role="example"><![CDATA[
-// create a simple 3d grid
-nx = 10; ny = 6; nz = 4;
-x = linspace(0,2,nx);
-y = linspace(0,1,ny);
-z = linspace(0,0.5,nz);
-[X,Y,Z] = ndgrid(x,y,z);
-
-// try to display this 3d grid ...
-XF=[]; YF=[]; ZF=[];
-
-for k=1:nz
- [xf,yf,zf] = nf3d(X(:,:,k),Y(:,:,k),Z(:,:,k));
- XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
-end
-
-for j=1:ny
- [xf,yf,zf] = nf3d(matrix(X(:,j,:),[nx,nz]),...
- matrix(Y(:,j,:),[nx,nz]),...
- matrix(Z(:,j,:),[nx,nz]));
- XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
-end
-
-clf()
-plot3d(XF,YF,ZF, flag=[0 6 3], leg="X@Y@Z")
-xtitle("A 3d grid !"); show_window()
+
+ <para>
+ <emphasis role="bold">Example #2:</emphasis>
+ </para>
+
+ <programlisting role="example"><![CDATA[ \r
+// Create a simple 3d grid\r
+nx = 10; ny = 6; nz = 4;\r
+x = linspace(0,2,nx);\r
+y = linspace(0,1,ny);\r
+z = linspace(0,0.5,nz);\r
+[X,Y,Z] = ndgrid(x,y,z);\r
+\r
+// Try to display this 3d grid ...\r
+XF=[]; YF=[]; ZF=[];\r
+\r
+for k=1:nz\r
+ [xf,yf,zf] = nf3d(X(:,:,k),Y(:,:,k),Z(:,:,k));\r
+ XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];\r
+end\r
+\r
+for j=1:ny\r
+ [xf,yf,zf] = nf3d(matrix(X(:,j,:),[nx,nz]),...\r
+ matrix(Y(:,j,:),[nx,nz]),...\r
+ matrix(Z(:,j,:),[nx,nz]));\r
+ XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];\r
+end\r
+\r
+clf()\r
+plot3d(XF,YF,ZF, flag=[0 6 3], 66, 61,leg="X@Y@Z")\r
+xtitle("A 3d grid !"); show_window()\r
]]></programlisting>
+
<scilab:image>
+
nx = 10; ny = 6; nz = 4;
+
x = linspace(0,2,nx);
+
y = linspace(0,1,ny);
+
z = linspace(0,0.5,nz);
+
[X,Y,Z] = ndgrid(x,y,z);
+
+
XF=[]; YF=[]; ZF=[];
+
+
for k=1:nz
+
[xf,yf,zf] = nf3d(X(:,:,k),Y(:,:,k),Z(:,:,k));
+
XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
+
end
+
+
for j=1:ny
+
[xf,yf,zf] = nf3d(matrix(X(:,j,:),[nx,nz]),...
+
matrix(Y(:,j,:),[nx,nz]),...
+
matrix(Z(:,j,:),[nx,nz]));
+
XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
+
end
- plot3d(XF,YF,ZF, flag=[0 6 3], leg="X@Y@Z")
+
+ plot3d(XF,YF,ZF, flag=[0 6 3], 66, 61, leg="X@Y@Z")
+
xtitle("A 3d grid !");
+
</scilab:image>
+
+
+
+ <para>
+ <emphasis role="bold">Example #3: Creates a table of digrams:</emphasis>
+ </para>
+
+ <programlisting role="example"><![CDATA[ \r
+[c1, c2] = ndgrid(["a" "b" "c"], ["a" "b" "c" "d" "e" "f" "g" "h"])\r
+c1+c2\r
+ ]]></programlisting>
+
+ <screen>
+
+ <![CDATA[--> [c1, c2] = ndgrid(["a" "b" "c"], ["a" "b" "c" "d" "e" "f" "g" "h"])\r
+ c2 = \r
+!a b c d e f g h !\r
+!a b c d e f g h !\r
+!a b c d e f g h !\r
+\r
+ c1 = \r
+!a a a a a a a a !\r
+!b b b b b b b b !\r
+!c c c c c c c c !\r
+\r
+--> c1+c2\r
+ ans =\r
+!aa ab ac ad ae af ag ah !\r
+!ba bb bc bd be bf bg bh !\r
+!ca cb cc cd ce cf cg ch !\r
+]]>
+ </screen>
+
</refsection>
+
<refsection role="see also">
+
<title>See Also</title>
+
<simplelist type="inline">
+
+ <member>
+
+ <link linkend="meshgrid">meshgrid</link>
+
+ </member>
+
<member>
+
<link linkend="kron">kron</link>
+
</member>
+
+ <member>
+
+ <link linkend="feval">feval</link>
+
+ </member>
+
+ <member>
+
+ <link linkend="eval3d">eval3d</link>
+
+ </member>
+
+ <member>
+
+ <link linkend="nf3d">nf3d</link>
+
+ </member>
+
</simplelist>
+
</refsection>
+
+ <refsection role="history">
+
+ <title>History</title>
+
+ <revhistory>
+
+ <revision>
+
+ <revnumber>6.0</revnumber>
+
+ <revdescription>Extension to all homogeneous datatypes ([],
+
+ booleans, encoded integers, polynomials, rationals, strings).
+
+ Revision of the help page.
+
+ </revdescription>
+
+ </revision>
+
+ </revhistory>
+
+ </refsection>
+
</refentry>
+
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>\r
-<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="en">\r
- <refnamediv>\r
- <refname>ndgrid</refname>\r
- <refpurpose>build matrices or N-D arrays by replicating some template vectors\r
- </refpurpose>\r
- </refnamediv>\r
- <refsynopsisdiv>\r
- <title>Calling Sequence</title>\r
- <synopsis>[X, Y] = ndgrid(x,y)\r
- [X, Y, Z] = ndgrid(x,y,z)\r
- [X, Y, Z, T] = ndgrid(x,y,z,t)\r
- [X1, X2, ..., Xm] = ndgrid(x1,x2,...,xm)\r
- </synopsis>\r
- </refsynopsisdiv>\r
- <refsection role="arguments">\r
- <title>Arguments</title>\r
- <variablelist>\r
- <varlistentry>\r
- <term>x, y, z, ...</term>\r
- <listitem>\r
- <para>vectors of any data types. They may have distinct data types.</para>\r
- </listitem>\r
- </varlistentry>\r
- <varlistentry>\r
- <term>X, Y, Z, ...</term>\r
- <listitem>\r
- <para>matrices in case of 2 input arguments, or hypermatrices otherwise.\r
- They all have the same sizes: size(X,"*") rows, size(Y,"*") columns, \r
- size(Z,"*") layers, etc. \r
- They have the datatypes of respective input vectors:\r
- <literal>typeof(X)==typeof(x)</literal>, \r
- <literal>typeof(Y)==typeof(y)</literal>, etc.\r
- </para>\r
- </listitem>\r
- </varlistentry>\r
- </variablelist>\r
- </refsection>\r
- <refsection role="description">\r
- <title>Description</title>\r
- <para>The first application of <function>ndgrid</function> is to build\r
- a grid of nodes meshing the 2D or 3D or N-D space according to 2, 3,\r
- or more sets\r
- <literal>x</literal>, <literal> y</literal>, etc.. of \r
- "template" coordinates sampled along each direction/dimension of the\r
- space that you want to mesh.\r
- </para>\r
- <para>Hence, the matrix or hypermatrix <literal>X</literal> is made\r
- by replicating the vector <literal>x</literal> as all its columns ; \r
- the matrix or hypermatrix <literal>Y</literal> is made\r
- by replicating the vector <literal>y</literal> as all its rows ;\r
- <literal>Z</literal> is made of replicating the vector \r
- <literal>z</literal> along all its local thicknesses (3rd dimension); \r
- etc\r
- </para>\r
- <screen>\r
-<![CDATA[--> [X, Y] = ndgrid([1 3 4], [0 2 4 6])\r
- X = \r
- 1. 1. 1. 1.\r
- 3. 3. 3. 3.\r
- 4. 4. 4. 4.\r
-\r
- Y = \r
- 0. 2. 4. 6.\r
- 0. 2. 4. 6.\r
- 0. 2. 4. 6.\r
-]]></screen>\r
- <para> \r
- Then, the coordinates of the node(i,j) in the 2D space \r
- will be\r
- simply <literal>[x(i), y(j)]</literal> now given by\r
- <literal>[X(i,j), Y(i,j)]</literal>. As well, the coordinates of a\r
- <literal>node(i,j,k)</literal> of a 3D grid will be \r
- <literal>[x(i), y(j), z(k)]</literal> now given by \r
- <literal>[X(i,j,k), Y(i,j,k), Z(i,j,k)]</literal>.\r
- </para>\r
- <para>\r
- This replication scheme can be generalized to any number of dimensions,\r
- as well to any type of uniform data. Let's for instance consider 2\r
- attributes:\r
- <orderedlist>\r
- <listitem>The first is a number, to be chosen from the vector say\r
- <literal>n = [ 3 7 ]</literal>\r
- </listitem>\r
- <listitem>The second is a letter, to be chosen from the vector \r
- say <literal>c = ["a" "e" "i" "o" "u" "y"]</literal>\r
- </listitem>\r
- </orderedlist>\r
- Then we want to build the set of all {n,c} possible pairs. It will\r
- just be the 2D grid:\r
- </para>\r
- <screen>\r
-<![CDATA[--> [N, C] = ndgrid([3 7],["a" "e" "i" "o" "u" "y"])\r
- C = \r
-!a e i o u y !\r
-!a e i o u y !\r
-\r
- N = \r
- 3. 3. 3. 3. 3. 3.\r
- 7. 7. 7. 7. 7. 7.\r
-]]></screen>\r
- <para>Then, the object(i,j) will have the properties \r
- <literal>{n(i) c(j)}</literal> that now can be addressed with\r
- <literal>{N(i,j) C(i,j)}</literal>.\r
- This kind of grid may be useful to initialize an array of structures.\r
- </para>\r
- <para>Following examples show how to use <varname>X, Y, Z</varname> in\r
- most frequent applications.\r
- </para> \r
- </refsection>\r
- <refsection role="examples">\r
- <title>Examples</title>\r
- <para><emphasis role="bold">Example #1:</emphasis> </para>\r
- <programlisting role="example"><![CDATA[ \r
-// Create a simple 2d grid\r
-x = linspace(-10,2,40);\r
-y = linspace(-5,5,40);\r
-[X,Y] = ndgrid(x,y);\r
-\r
-// Compute ordinates Z(X,Y) on the {X, Y} grid and plot Z(X,Y)\r
-Z = X - 3*X.*sin(X).*cos(Y-4) ;\r
-clf()\r
-plot3d(x,y,Z, flag=[color("green") 2 4], alpha=7, theta=60); show_window()\r
- ]]></programlisting>\r
- <scilab:image>\r
- x = linspace(-10,2,40);\r
- y = linspace(-5,5,40);\r
- [X,Y] = ndgrid(x,y);\r
- Z = X - 3*X.*sin(X).*cos(Y-4) ;\r
- clf()\r
- plot3d(x,y,Z, flag=[color("green") 2 4], alpha=7, theta=60); show_window()\r
- </scilab:image>\r
- <para><emphasis role="bold">Example #2:</emphasis> </para>\r
- <programlisting role="example"><![CDATA[ \r
-// Create a simple 3d grid\r
-nx = 10; ny = 6; nz = 4;\r
-x = linspace(0,2,nx);\r
-y = linspace(0,1,ny);\r
-z = linspace(0,0.5,nz);\r
-[X,Y,Z] = ndgrid(x,y,z);\r
-\r
-// Try to display this 3d grid ...\r
-XF=[]; YF=[]; ZF=[];\r
-\r
-for k=1:nz\r
- [xf,yf,zf] = nf3d(X(:,:,k),Y(:,:,k),Z(:,:,k));\r
- XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];\r
-end\r
-\r
-for j=1:ny\r
- [xf,yf,zf] = nf3d(matrix(X(:,j,:),[nx,nz]),...\r
- matrix(Y(:,j,:),[nx,nz]),...\r
- matrix(Z(:,j,:),[nx,nz]));\r
- XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];\r
-end\r
-\r
-clf()\r
-plot3d(XF,YF,ZF, flag=[0 6 3], 66, 61,leg="X@Y@Z")\r
-xtitle("A 3d grid !"); show_window()\r
- ]]></programlisting>\r
- <scilab:image>\r
- nx = 10; ny = 6; nz = 4;\r
- x = linspace(0,2,nx);\r
- y = linspace(0,1,ny);\r
- z = linspace(0,0.5,nz);\r
- [X,Y,Z] = ndgrid(x,y,z);\r
- \r
- XF=[]; YF=[]; ZF=[];\r
- \r
- for k=1:nz\r
- [xf,yf,zf] = nf3d(X(:,:,k),Y(:,:,k),Z(:,:,k));\r
- XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];\r
- end\r
- \r
- for j=1:ny\r
- [xf,yf,zf] = nf3d(matrix(X(:,j,:),[nx,nz]),...\r
- matrix(Y(:,j,:),[nx,nz]),...\r
- matrix(Z(:,j,:),[nx,nz]));\r
- XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];\r
- end\r
- plot3d(XF,YF,ZF, flag=[0 6 3], 66, 61, leg="X@Y@Z")\r
- xtitle("A 3d grid !"); \r
- </scilab:image>\r
-\r
- <para><emphasis role="bold">Example #3: Creates a table of digrams:</emphasis> </para>\r
- <programlisting role="example"><![CDATA[ \r
-[c1, c2] = ndgrid(["a" "b" "c"], ["a" "b" "c" "d" "e" "f" "g" "h"])\r
-c1+c2\r
- ]]></programlisting>\r
- <screen>\r
-<![CDATA[--> [c1, c2] = ndgrid(["a" "b" "c"], ["a" "b" "c" "d" "e" "f" "g" "h"])\r
- c2 = \r
-!a b c d e f g h !\r
-!a b c d e f g h !\r
-!a b c d e f g h !\r
-\r
- c1 = \r
-!a a a a a a a a !\r
-!b b b b b b b b !\r
-!c c c c c c c c !\r
-\r
---> c1+c2\r
- ans =\r
-!aa ab ac ad ae af ag ah !\r
-!ba bb bc bd be bf bg bh !\r
-!ca cb cc cd ce cf cg ch !\r
-]]></screen>\r
- </refsection>\r
- <refsection role="see also">\r
- <title>See Also</title>\r
- <simplelist type="inline">\r
- <member>\r
- <link linkend="meshgrid">meshgrid</link>\r
- </member>\r
- <member>\r
- <link linkend="kron">kron</link>\r
- </member>\r
- <member>\r
- <link linkend="feval">feval</link>\r
- </member>\r
- <member>\r
- <link linkend="eval3d">eval3d</link>\r
- </member>\r
- <member>\r
- <link linkend="nf3d">nf3d</link>\r
- </member>\r
- </simplelist>\r
- </refsection>\r
- <refsection role="history">\r
- <title>History</title>\r
- <revhistory>\r
- <revision>\r
- <revnumber>6.0</revnumber>\r
- <revdescription>Extension to all homogeneous datatypes ([], \r
- booleans, encoded integers, polynomials, rationals, strings). \r
- Revision of the help page.\r
- </revdescription>\r
- </revision>\r
- </revhistory>\r
- </refsection>\r
-</refentry>\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<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="fr">
+
+ <refnamediv>
+
+ <refname>ndgrid</refname>
+
+ <refpurpose>construit des matrices ou hypermatrices en répliquant des vecteurs
+
+ </refpurpose>
+
+ </refnamediv>
+
+ <refsynopsisdiv>
+
+ <title>Séquences d'appel</title>
+
+ <synopsis>[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)
+
+ </synopsis>
+
+ </refsynopsisdiv>
+
+ <refsection role="arguments">
+
+ <title>Paramètres</title>
+
+ <variablelist>
+
+ <varlistentry>
+
+ <term>x, y, z, ...</term>
+
+ <listitem>
+
+ <para>vecteurs de types simples quelconques possiblement
+
+ distincts (booléens,
+
+ entiers encodés, décimaux, complexes, polynômes, rationnels,
+
+ textes).
+ </para>
+
+ </listitem>
+
+ </varlistentry>
+
+ <varlistentry>
+
+ <term>X, Y, Z, ...</term>
+
+ <listitem>
+
+ <para>Matrices (si seulement 2 vecteurs d'entrée),
+
+ ou hypermatrices, toutes de tailles identiques :
+ size(x,"*") lignes, size(y,"*") colonnes,
+
+ size(z,"*") feuilles, etc.
+ </para>
+ <para>Par ailleurs,
+ <varname>X</varname> a le type de <varname>x</varname>;
+
+ <varname>Y</varname> a le type de <varname>y</varname>;
+
+ etc.
+
+ </para>
+
+ </listitem>
+
+ </varlistentry>
+
+ </variablelist>
+
+ </refsection>
+
+ <refsection role="description">
+
+ <title>Description</title>
+
+ <para>
+ La première application de <function>ndgrid</function> consiste à
+
+ construire une grille multidimensionnelle de noeuds échantillonnant
+
+ l'espace 2D ou 3D ou N-D, à partir de 2, 3 ou N vecteurs
+
+ <literal>x</literal>, <literal> y</literal>, etc.. indiquant
+
+ l'échantillonage de chaque direction de l'espace.
+
+ </para>
+
+ <para>Pour ce faire,
+
+ <itemizedlist>
+
+ <listitem>la matrice ou l'hypermatrice <literal>X</literal>
+
+ est construite en répliquant le vecteur <literal>x</literal>
+
+ dans toutes ses colonnes ;
+
+ </listitem>
+
+
+ <listitem>
+ la matrice ou l'hypermatrice <literal>Y</literal>
+
+ est construite en répliquant le vecteur <literal>y</literal>
+
+ dans toutes ses lignes ;
+
+ </listitem>
+
+
+ <listitem>
+ la matrice ou l'hypermatrice <literal>Z</literal>
+
+ est construite en répliquant le vecteur <literal>z</literal>
+
+ en épaisseur pour tous les points (x,y) ;
+
+ etc.
+
+ </listitem>
+
+ </itemizedlist>
+
+ </para>
+
+ <screen>
+
+ <![CDATA[--> [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.
+]]>
+ </screen>
+
+ <para>
+
+ Les coordonnées du noeud node(i,j) dans l'espace 2D seront alors
+
+ simplement <literal>[x(i), y(j)]</literal> maintenant données par
+
+ <literal>[X(i,j), Y(i,j)]</literal>. De même, les coordonnées du noeud
+
+ <literal>node(i,j,k)</literal> dans une grille 3D seront
+
+ <literal>[x(i), y(j), z(k)]</literal> données par
+
+ <literal>[X(i,j,k), Y(i,j,k), Z(i,j,k)]</literal>.
+
+ </para>
+
+ <para>Ce schéma de construction par réplication peut être utilisé
+
+ pour construire une grille à un nombre N quelconque de dimensions.
+
+ Par ailleurs, il est indépendant de la nature des vecteurs de base répliqués
+
+ et peut donc être utilisé pour tous les types de données uniformes.
+
+ A titre d'exemple, considérons un ensemble d'objets ayant tous 2 attributs :
+
+ <orderedlist>
+
+ <listitem>
+ Le premier est un nombre <literal>n</literal>,
+
+ avec 2 valeurs possibles, par exemple: <literal>n = [ 3 7 ]</literal>
+
+ </listitem>
+
+ <listitem>Le second est une lettre, avec 6 choix possibles,
+
+ par exemple: <literal>c = ["a" "e" "i" "o" "u" "y"]</literal>
+
+ </listitem>
+
+ </orderedlist>
+
+ Nous souhaitons maintenant générer l'ensemble complet des
+
+ objets {n,c} possibles. Il s'agit juste d'une grille 2D
+
+ d'<literal>objets</literal> :
+
+ </para>
+
+ <screen>
+
+ <![CDATA[--> [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.
+]]>
+ </screen>
+
+ <para>De là, l'objet(i,j) aura les attributs
+
+ <literal>{n(i) c(j)}</literal> que l'on pourra maintenant désigner par
+
+ <literal>{N(i,j) C(i,j)}</literal>.
+
+ Ce type de grille pourra être utilisée pour initialiser un tableau
+
+ 2D de structures ayant 2 champs <literal>n</literal> et <literal>c</literal>.
+
+ </para>
+
+ <para>Les exemples suivants montrent comment utiliser les matrices ou
+
+ hypermatrices <varname>X, Y, Z</varname> produites, pour des applications
+
+ usuelles.
+
+ </para>
+
+
+</refsection>
+
+<refsection role="examples">
+
+ <title>Exemples</title>
+
+
+
+ <para>
+ <emphasis role="bold">Exemple #1:</emphasis>
+ </para>
+
+ <programlisting role="example"><![CDATA[
+// Créons une grille de points {X,Y}
+x = linspace(-10,2,40);
+y = linspace(-5,5,40);
+[X,Y] = ndgrid(x,y); // x et y sont répliqués pour créer la grille
+
+// Calculons des ordonnées Z(X,Y) et traçons Z(X,Y) :
+Z = X - 3*X.*sin(X).*cos(Y-4) ;
+clf()
+plot3d(x,y,Z, flag=[color("green") 2 4], alpha=7, theta=60); show_window()
+ ]]></programlisting>
+
+ <scilab:image>
+
+ x = linspace(-10,2,40);
+
+ y = linspace(-5,5,40);
+
+ [X,Y] = ndgrid(x,y);
+
+ Z = X - 3*X.*sin(X).*cos(Y-4) ;
+
+ clf()
+
+ plot3d(x,y,Z, flag=[color("green") 2 4], alpha=7, theta=60); show_window()
+
+ </scilab:image>
+
+
+
+ <para>
+ <emphasis role="bold">Exemple #2:</emphasis>
+ </para>
+
+ <programlisting role="example"><![CDATA[
+// Créons une grille en 3 dimensions
+nx = 10; ny = 6; nz = 4;
+x = linspace(0,2,nx);
+y = linspace(0,1,ny);
+z = linspace(0,0.5,nz);
+[X,Y,Z] = ndgrid(x,y,z);
+
+// Nous choisissons ici une représentation cartésienne, mais l'on pourrait
+// aussi travailler en coordonnées cylindriques, sphériques, ou autres.
+// Transformons les coordonnées pour plot3d() :
+XF=[]; YF=[]; ZF=[];
+
+for k=1:nz
+ [xf,yf,zf] = nf3d(X(:,:,k),Y(:,:,k),Z(:,:,k));
+ XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
+end
+
+for j=1:ny
+ [xf,yf,zf] = nf3d(matrix(X(:,j,:),[nx,nz]),...
+ matrix(Y(:,j,:),[nx,nz]),...
+ matrix(Z(:,j,:),[nx,nz]));
+ XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
+end
+
+// Affichage :
+clf()
+plot3d(XF,YF,ZF, flag=[0 6 3], 66, 61, leg="X@Y@Z")
+xtitle("A 3d grid !"); show_window()
+ ]]></programlisting>
+
+ <scilab:image>
+
+ nx = 10; ny = 6; nz = 4;
+
+ x = linspace(0,2,nx);
+
+ y = linspace(0,1,ny);
+
+ z = linspace(0,0.5,nz);
+
+ [X,Y,Z] = ndgrid(x,y,z);
+
+
+
+ XF=[]; YF=[]; ZF=[];
+
+
+
+ for k=1:nz
+
+ [xf,yf,zf] = nf3d(X(:,:,k),Y(:,:,k),Z(:,:,k));
+
+ XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
+
+ end
+
+
+
+ for j=1:ny
+
+ [xf,yf,zf] = nf3d(matrix(X(:,j,:),[nx,nz]),...
+
+ matrix(Y(:,j,:),[nx,nz]),...
+
+ matrix(Z(:,j,:),[nx,nz]));
+
+ XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
+
+ end
+
+ plot3d(XF,YF,ZF, flag=[0 6 3], 66, 61, leg="X@Y@Z")
+
+ xtitle("A 3d grid !");
+
+ </scilab:image>
+
+ <para>
+ <emphasis role="bold">Exemple #3: création d'une table de digrammes</emphasis>
+ </para>
+
+ <programlisting role="example"><![CDATA[
+[c1, c2] = ndgrid(["a" "b" "c"], ["a" "b" "c" "d" "e" "f" "g" "h"])
+c1+c2
+ ]]></programlisting>
+
+ <screen>
+
+ <![CDATA[--> [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 !
+]]>
+ </screen>
+
+</refsection>
+
+<refsection role="see also">
+
+ <title>Voir aussi</title>
+
+ <simplelist type="inline">
+
+ <member>
+
+ <link linkend="meshgrid">meshgrid</link>
+
+ </member>
+
+ <member>
+
+ <link linkend="kron">kron</link>
+
+ </member>
+
+ <member>
+
+ <link linkend="feval">feval</link>
+
+ </member>
+
+ <member>
+
+ <link linkend="eval3d">eval3d</link>
+
+ </member>
+
+ <member>
+
+ <link linkend="nf3d">nf3d</link>
+
+ </member>
+
+ </simplelist>
+
+</refsection>
+
+<refsection role="history">
+
+ <title>Historique</title>
+
+ <revhistory>
+
+ <revision>
+
+ <revnumber>6.0</revnumber>
+
+ <revdescription>Extension à tous les types de données uniformes ([], booleans, encoded integers, polynomials, rationals, strings). Révision de la page d'aide.
+
+ </revdescription>
+
+ </revision>
+
+ </revhistory>
+
+</refsection>
+
+</refentry>
+
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>\r
-<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="fr">\r
- <refnamediv>\r
- <refname>ndgrid</refname>\r
- <refpurpose>construit des matrices ou hypermatrices en répliquant des vecteurs\r
- </refpurpose>\r
- </refnamediv>\r
- <refsynopsisdiv>\r
- <title>Séquences d'appel</title>\r
- <synopsis>[X, Y] = ndgrid(x,y)\r
- [X, Y, Z] = ndgrid(x,y,z)\r
- [X, Y, Z, T] = ndgrid(x,y,z,t)\r
- [X1, X2, ..., Xm] = ndgrid(x1,x2,...,xm)\r
- </synopsis>\r
- </refsynopsisdiv>\r
- <refsection role="arguments">\r
- <title>Paramètres</title>\r
- <variablelist>\r
- <varlistentry>\r
- <term>x, y, z, ...</term>\r
- <listitem>\r
- <para>vecteurs de types simples quelconques possiblement\r
- distincts (booléens, \r
- entiers encodés, décimaux, complexes, polynômes, rationnels,\r
- textes).</para>\r
- </listitem>\r
- </varlistentry>\r
- <varlistentry>\r
- <term>X, Y, Z, ...</term>\r
- <listitem>\r
- <para>Matrices (si seulement 2 vecteurs d'entrée),\r
- ou hypermatrices avec autant de dimensions qu'il y a de \r
- vecteurs d'entrée <literal>x1, x2, ..., xn</literal>.\r
- <varname>X</varname> a le type de <varname>x</varname> ; \r
- <varname>Y</varname> a le type de <varname>y</varname> ; \r
- etc. \r
- </para>\r
- </listitem>\r
- </varlistentry>\r
- </variablelist>\r
- </refsection>\r
- <refsection role="description">\r
- <title>Description</title>\r
- <para>La première application de <function>ndgrid</function> consiste à\r
- construire une grille multidimensionnelle de noeuds échantillonnant\r
- l'espace 2D ou 3D ou N-D, à partir de 2, 3 ou N vecteurs \r
- <literal>x</literal>, <literal> y</literal>, etc.. indiquant \r
- l'échantillonage de chaque direction de l'espace.\r
- </para>\r
- <para>Pour ce faire, \r
- <itemizedlist>\r
- <listitem></listitem>la matrice ou l'hypermatrice <literal>X</literal> \r
- est construite en répliquant le vecteur <literal>x</literal> \r
- dans toutes ses colonnes ;\r
- </listitem> \r
- <listitem>la matrice ou l'hypermatrice <literal>Y</literal> \r
- est construite en répliquant le vecteur <literal>y</literal> \r
- dans toutes ses lignes ;\r
- </listitem> \r
- <listitem>la matrice ou l'hypermatrice <literal>Z</literal> \r
- est construite en répliquant le vecteur <literal>z</literal> \r
- en épaisseur pour tous les points (x,y) ; \r
- etc.\r
- </listitem>\r
- </itemizedlist>\r
- </para>\r
- <screen>\r
-<![CDATA[--> [X, Y] = ndgrid([1 3 4], [0 2 4 6])\r
- X = \r
- 1. 1. 1. 1.\r
- 3. 3. 3. 3.\r
- 4. 4. 4. 4.\r
-\r
- Y = \r
- 0. 2. 4. 6.\r
- 0. 2. 4. 6.\r
- 0. 2. 4. 6.\r
-]]></screen>\r
- <para>\r
- Les coordonnées du noeud node(i,j) dans l'espace 2D seront alors \r
- simplement <literal>[x(i), y(j)]</literal> maintenant données par\r
- <literal>[X(i,j), Y(i,j)]</literal>. De même, les coordonnées du noeud\r
- <literal>node(i,j,k)</literal> dans une grille 3D seront\r
- <literal>[x(i), y(j), z(k)]</literal> données par\r
- <literal>[X(i,j,k), Y(i,j,k), Z(i,j,k)]</literal>.\r
- </para>\r
- <para>Ce schéma de construction par réplication peut être utilisé\r
- pour construire une grille à un nombre N quelconque de dimensions.\r
- Par ailleurs, il est indépendant de la nature des vecteurs de base répliqués\r
- et peut donc être utilisé pour tous les types de données uniformes.\r
- A titre d'exemple, considérons un ensemble d'objets ayant tous 2 attributs :\r
- <orderedlist>\r
- <listitem>Le premier est un nombre <literal>n</literal>, \r
- avec 2 valeurs possibles, par exemple: <literal>n = [ 3 7 ]</literal>\r
- </listitem>\r
- <listitem>Le second est une lettre, avec 6 choix possibles, \r
- par exemple: <literal>c = ["a" "e" "i" "o" "u" "y"]</literal>\r
- </listitem>\r
- </orderedlist>\r
- Nous souhaitons maintenant générer l'ensemble complet des \r
- objets {n,c} possibles. Il s'agit juste d'une grille 2D \r
- d'<literal>objets</literal> :\r
- </para>\r
- <screen>\r
-<![CDATA[--> [X, Y] = ndgrid([1 3 4], [0 2 4 6])\r
- X = \r
- 1. 1. 1. 1.\r
- 3. 3. 3. 3.\r
- 4. 4. 4. 4.\r
-\r
- Y = \r
- 0. 2. 4. 6.\r
- 0. 2. 4. 6.\r
- 0. 2. 4. 6.\r
-]]></screen>\r
- <para>De là, l'objet(i,j) aura les attributs\r
- <literal>{n(i) c(j)}</literal> que l'on pourra maintenant désigner par \r
- <literal>{N(i,j) C(i,j)}</literal>.\r
- Ce type de grille pourra être utilisée pour initialiser un tableau \r
- 2D de structures ayant 2 champs <literal>n</literal> et <literal>c</literal>.\r
- </para>\r
- <para>Les exemples suivants montrent comment utiliser les matrices ou\r
- hypermatrices <varname>X, Y, Z</varname> produites, pour des applications\r
- usuelles.\r
- </para> \r
- </refsection>\r
- <refsection role="examples">\r
- <title>Exemples</title>\r
-\r
- <para><emphasis role="bold">Exemple #1:</emphasis> </para>\r
- <programlisting role="example"><![CDATA[ \r
-// Créons une grille de points {X,Y}\r
-x = linspace(-10,2,40);\r
-y = linspace(-5,5,40);\r
-[X,Y] = ndgrid(x,y); // x et y sont répliqués pour créer la grille\r
-\r
-// Calculons des ordonnées Z(X,Y) et traçons Z(X,Y) :\r
-Z = X - 3*X.*sin(X).*cos(Y-4) ;\r
-clf()\r
-plot3d(x,y,Z, flag=[color("green") 2 4], alpha=7, theta=60); show_window()\r
- ]]></programlisting>\r
- <scilab:image>\r
- x = linspace(-10,2,40);\r
- y = linspace(-5,5,40);\r
- [X,Y] = ndgrid(x,y);\r
- Z = X - 3*X.*sin(X).*cos(Y-4) ;\r
- clf()\r
- plot3d(x,y,Z, flag=[color("green") 2 4], alpha=7, theta=60); show_window()\r
- </scilab:image>\r
-\r
- <para><emphasis role="bold">Exemple #2:</emphasis> </para>\r
- <programlisting role="example"><![CDATA[ \r
-// Créons une grille en 3 dimensions\r
-nx = 10; ny = 6; nz = 4;\r
-x = linspace(0,2,nx);\r
-y = linspace(0,1,ny);\r
-z = linspace(0,0.5,nz);\r
-[X,Y,Z] = ndgrid(x,y,z);\r
-\r
-// Nous choisissons ici une représentation cartésienne, mais l'on pourrait\r
-// aussi travailler en coordonnées cylindriques, sphériques, ou autres. \r
-// Transformons les coordonnées pour plot3d() :\r
-XF=[]; YF=[]; ZF=[];\r
-\r
-for k=1:nz\r
- [xf,yf,zf] = nf3d(X(:,:,k),Y(:,:,k),Z(:,:,k));\r
- XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];\r
-end\r
-\r
-for j=1:ny\r
- [xf,yf,zf] = nf3d(matrix(X(:,j,:),[nx,nz]),...\r
- matrix(Y(:,j,:),[nx,nz]),...\r
- matrix(Z(:,j,:),[nx,nz]));\r
- XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];\r
-end\r
-\r
-// Affichage :\r
-clf()\r
-plot3d(XF,YF,ZF, flag=[0 6 3], 66, 61, leg="X@Y@Z")\r
-xtitle("A 3d grid !"); show_window()\r
- ]]></programlisting>\r
- <scilab:image>\r
- nx = 10; ny = 6; nz = 4;\r
- x = linspace(0,2,nx);\r
- y = linspace(0,1,ny);\r
- z = linspace(0,0.5,nz);\r
- [X,Y,Z] = ndgrid(x,y,z);\r
- \r
- XF=[]; YF=[]; ZF=[];\r
- \r
- for k=1:nz\r
- [xf,yf,zf] = nf3d(X(:,:,k),Y(:,:,k),Z(:,:,k));\r
- XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];\r
- end\r
- \r
- for j=1:ny\r
- [xf,yf,zf] = nf3d(matrix(X(:,j,:),[nx,nz]),...\r
- matrix(Y(:,j,:),[nx,nz]),...\r
- matrix(Z(:,j,:),[nx,nz]));\r
- XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];\r
- end\r
- plot3d(XF,YF,ZF, flag=[0 6 3], 66, 61, leg="X@Y@Z")\r
- xtitle("A 3d grid !"); \r
- </scilab:image>\r
- <para><emphasis role="bold">Exemple #3: création d'une table de digrammes</emphasis> </para>\r
- <programlisting role="example"><![CDATA[ \r
-[c1, c2] = ndgrid(["a" "b" "c"], ["a" "b" "c" "d" "e" "f" "g" "h"])\r
-c1+c2\r
- ]]></programlisting>\r
- <screen>\r
-<![CDATA[--> [c1, c2] = ndgrid(["a" "b" "c"], ["a" "b" "c" "d" "e" "f" "g" "h"])\r
- c2 = \r
-!a b c d e f g h !\r
-!a b c d e f g h !\r
-!a b c d e f g h !\r
-\r
- c1 = \r
-!a a a a a a a a !\r
-!b b b b b b b b !\r
-!c c c c c c c c !\r
-\r
---> c1+c2\r
- ans =\r
-!aa ab ac ad ae af ag ah !\r
-!ba bb bc bd be bf bg bh !\r
-!ca cb cc cd ce cf cg ch !\r
-]]></screen>\r
- </refsection>\r
- <refsection role="see also">\r
- <title>Voir aussi</title>\r
- <simplelist type="inline">\r
- <member>\r
- <link linkend="meshgrid">meshgrid</link>\r
- </member>\r
- <member>\r
- <link linkend="kron">kron</link>\r
- </member>\r
- <member>\r
- <link linkend="feval">feval</link>\r
- </member>\r
- <member>\r
- <link linkend="eval3d">eval3d</link>\r
- </member>\r
- <member>\r
- <link linkend="nf3d">nf3d</link>\r
- </member>\r
- </simplelist>\r
- </refsection>\r
- <refsection role="history">\r
- <title>Historique</title>\r
- <revhistory>\r
- <revision>\r
- <revnumber>6.0</revnumber>\r
- <revdescription>Extension à tous les types de données uniformes ([], booleans, encoded integers, polynomials, rationals, strings). Révision de la page d'aide.\r
- </revdescription>\r
- </revision>\r
- </revhistory>\r
- </refsection>\r
-</refentry>\r
<?xml version="1.0" encoding="UTF-8"?>
<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="ja">
+
+<refnamediv>
- <refnamediv>
-
- <refname>ndgrid</refname>
-
- <refpurpose>
-
- 多次元関数評価用グリッドの配列
-
- </refpurpose>
+ <refname>ndgrid</refname>
+
+ <refpurpose>与えられたベクトルを複製することによって、行列またはN次元配列を作成
- </refnamediv>
+ </refpurpose>
- <refsynopsisdiv>
+</refnamediv>
+
+<refsynopsisdiv>
+
+ <title>呼び出し手順</title>
+
+ <synopsis>[X, Y] = ndgrid(x,y)
- <title>呼び出し手順</title>
+ [X, Y, Z] = ndgrid(x,y,z)
- <synopsis>[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)
-
- </synopsis>
+ [X, Y, Z, T] = ndgrid(x,y,z,t)
- </refsynopsisdiv>
-
- <refsection>
+ [X1, X2, ..., Xm] = ndgrid(x1,x2,...,xm)
- <title>引数</title>
+ </synopsis>
+
+</refsynopsisdiv>
+
+<refsection role="arguments">
+
+ <title>引数</title>
+
+ <variablelist>
- <variablelist>
+ <varlistentry>
- <varlistentry>
-
- <term>x, y, z, ...</term>
-
- <listitem>
-
- <para>ベクトル</para>
-
- </listitem>
-
- </varlistentry>
+ <term>x, y, z, ...</term>
- <varlistentry>
+ <listitem>
- <term>X, Y, Z, ...</term>
+ <para>vectors of any data types. They may have distinct data types.</para>
+ </listitem>
+
+ </varlistentry>
+
+ <varlistentry>
+
+ <term>X, Y, Z, ...</term>
+
<listitem>
-
- <para>
+ <para>Matrices in case of 2 input arguments, or hypermatrices otherwise.
- 入力引数が2個の場合は行列,
+ They all have the same sizes: size(x,"*") rows, size(y,"*") columns,
- それ以外の場合はハイパー行列
+ size(z,"*") layers, etc.
+ </para>
+ <para>
+
+ They have the datatypes of respective input vectors:
+
+ <literal>typeof(X)==typeof(x)</literal>,
+
+ <literal>typeof(Y)==typeof(y)</literal>, etc.
</para>
</listitem>
-
- </varlistentry>
-
- </variablelist>
+ </varlistentry>
- </refsection>
+ </variablelist>
+
+</refsection>
+
+<refsection role="description">
+
+ <title>説明</title>
- <refsection>
+ <para>
+ The first application of <function>ndgrid</function> is to build
- <title>説明</title>
+ a grid of nodes meshing the 2D or 3D or N-D space according to 2, 3,
- <para>
-
- この関数はユーティリティルーチンで,
-
- 2, 3, ..., n次元のグリッド上で関数の評価を行う
-
- ための配列を作成する際に便利です.
-
- 例えば, 2次元の場合, グリッドは
-
- 長さ nx および nyの
-
- 2つのベクトル
-
- <literal>x</literal> および <literal> y</literal>
-
- で定義され,
-
- <emphasis>i=1,..,nx</emphasis> および <emphasis>j=1,..,ny</emphasis>
-
- として,座標<emphasis>(x(i),y(j))</emphasis>となります.
-
- そのグリッド上で (例えば<emphasis>f</emphasis>のような)関数の評価を
-
- 行うことになります.
-
- この場合,この関数は,以下のような大きさ<emphasis>nx x ny</emphasis>の
-
- 2つの行列<literal>X,Y</literal>を計算します :
-
- </para>
+ or more sets
- <programlisting role="no-scilab-exec"><![CDATA[
-X(i,j) = x(i) for all i in [1,nx]
-Y(i,j) = y(j) and j in [1,ny]
- ]]></programlisting>
+ <literal>x</literal>, <literal> y</literal>, etc.. of
- <para>
-
- 評価は,<literal>Z=f(X,Y)</literal>で行うことができます.
-
- (ベクトル引数で<literal>f</literal>を評価するようコードが
-
- 作成されている場合,
-
- <literal>*</literal>,
-
- <literal>/</literal> および <literal>^</literal>の部分に
-
- 要素毎の演算 <literal>.*</literal>, <literal>./</literal> および
-
- <literal>.^</literal>を使用することにより,(一般に)動作します..
-
- </para>
+ "template" coordinates sampled along each direction/dimension of the
- <para>
-
- 3次元の場合, 長さ nx, ny および nzの3個のベクトル<literal>x,y,z</literal>
-
- を指定し,
-
- <literal>X,Y,Z</literal>は以下のように大きさ
-
- <emphasis>nx x ny x nz</emphasis>のハイパー行列となります :
-
- </para>
+ space that you want to mesh.
- <programlisting role="no-scilab-exec"><![CDATA[
-X(i,j,k) = x(i)
-Y(i,j,k) = y(j) for all (i,j,k) in [1,nx]x[1,ny]x[1,nz]
-Z(i,j,k) = z(k)
- ]]></programlisting>
+ </para>
+
+ <para>
+ Hence, the matrix or hypermatrix <literal>X</literal> is made
+
+ by replicating the vector <literal>x</literal> as all its columns;
+
+ the matrix or hypermatrix <literal>Y</literal> is made
+
+ by replicating the vector <literal>y</literal> as all its rows;
- <para>
+ <literal>Z</literal> is made of replicating the vector
+
+ <literal>z</literal> along all its local thicknesses (3rd dimension);
+
+ etc
+
+ </para>
+
+ <screen>
+
+ <![CDATA[--> [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.
+]]>
+ </screen>
+
+ <para>
+
+ Then, the coordinates of the node(i,j) in the 2D space
+
+ will be
+
+ simply <literal>[x(i), y(j)]</literal> equal to
+
+ <literal>[X(i,j), Y(i,j)]</literal>. As well, the coordinates of a
+
+ <literal>node(i,j,k)</literal> of a 3D grid will be
+
+ <literal>[x(i), y(j), z(k)]</literal> equal to
+
+ <literal>[X(i,j,k), Y(i,j,k), Z(i,j,k)]</literal>.
+
+ </para>
+
+ <para>
+
+ 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:
+
+ <orderedlist>
- 一般的な場合, m 個の入力引数<literal>x1, x2, ..,
+ <listitem>The first is a number, to be chosen from the vector say
- xm
+ <literal>n = [ 3 7 ]</literal>
- </literal>
-
- ,それから m個の出力引数
+ </listitem>
- <literal>X1, X2, .., Xm</literal> は以下のような
-
- 大きさ <emphasis>nx1 x nx2 x ... x
+ <listitem>The second is a letter, to be chosen from the vector
- nxm
+ say <literal>c = ["a" "e" "i" "o" "u" "y"]</literal>
- </emphasis>
-
- のハイパー行列となります :
+ </listitem>
- </para>
+ </orderedlist>
- <programlisting role="no-scilab-exec"><![CDATA[
-Xj(i1,i2,...,ij,...,im) = xj(ij)
-for all (i1,i2,...,im) in [1,nx1]x[1,nx2]x...x[1,nxm]
- ]]></programlisting>
+ Then we want to build the set of all {n,c} possible pairs. It will
+
+ just be the 2D grid:
+
+ </para>
+
+ <screen>
+
+ <![CDATA[--> [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.
+]]>
+ </screen>
+
+ <para>Then, the object(i,j) will have the properties
+
+ <literal>{n(i) c(j)}</literal> that now can be addressed with
+
+ <literal>{N(i,j) C(i,j)}</literal>.
- </refsection>
+ This kind of grid may be useful to initialize an array of structures.
+
+ </para>
- <refsection>
+ <para>
+ Following examples show how to use <varname>X, Y, Z</varname> in
- <title>例</title>
+ most frequent applications.
- <programlisting role="example"><![CDATA[
-// 簡単な2次元グリッドを作
-nx = 40; ny = 40;
-x = linspace(-1,1,nx);
-y = linspace(-1,1,ny);
+ </para>
+
+
+</refsection>
+
+<refsection role="examples">
+
+ <title>例</title>
+
+
+
+ <para>
+ <emphasis role="bold">Example #1:</emphasis>
+ </para>
+
+ <programlisting role="example"><![CDATA[
+// Create a simple 2d grid
+x = linspace(-10,2,40);
+y = linspace(-5,5,40);
[X,Y] = ndgrid(x,y);
-// グリッド上で関数を計算してプロット
-//deff("z=f(x,y)","z=128*x.^2 .*(1-x).^2 .*y.^2 .*(1-y).^2");
-deff("z=f(x,y)","z=x.^2 + y.^3")
-Z = f(X,Y);
+
+// Compute ordinates Z(X,Y) on the {X, Y} grid and plot Z(X,Y)
+Z = X - 3*X.*sin(X).*cos(Y-4) ;
clf()
-plot3d(x,y,Z, flag=[2 6 4]); show_window()
+plot3d(x,y,Z, flag=[color("green") 2 4], alpha=7, theta=60); show_window()
]]></programlisting>
+
+ <scilab:image>
- <scilab:image>
-
- nx = 40; ny = 40;
-
- x = linspace(-1,1,nx);
-
- y = linspace(-1,1,ny);
-
- [X,Y] = ndgrid(x,y);
-
- deff("z=f(x,y)","z=x.^2 + y.^3")
-
- Z = f(X,Y);
-
- plot3d(x,y,Z, flag=[2 6 4]);
-
- </scilab:image>
+ x = linspace(-10,2,40);
+
+ y = linspace(-5,5,40);
+
+ [X,Y] = ndgrid(x,y);
+
+ Z = X - 3*X.*sin(X).*cos(Y-4) ;
- <programlisting role="example"><![CDATA[
+ clf()
+
+ plot3d(x,y,Z, flag=[color("green") 2 4], alpha=7, theta=60); show_window()
+
+ </scilab:image>
+
+
+
+ <para>
+ <emphasis role="bold">Example #2:</emphasis>
+ </para>
+
+ <programlisting role="example"><![CDATA[
// 簡単な3次元グリッドを作成
nx = 10; ny = 6; nz = 4;
x = linspace(0,2,nx);
XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
end
clf()
-plot3d(XF,YF,ZF, flag=[0 6 3], leg="X@Y@Z")
+plot3d(XF,YF,ZF, flag=[0 6 3], 66, 61, leg="X@Y@Z")
xtitle("A 3d grid !"); show_window()
]]></programlisting>
+
+ <scilab:image>
- <scilab:image>
-
- nx = 10; ny = 6; nz = 4;
-
- x = linspace(0,2,nx);
-
- y = linspace(0,1,ny);
-
- z = linspace(0,0.5,nz);
-
- [X,Y,Z] = ndgrid(x,y,z);
-
-
-
- XF=[]; YF=[]; ZF=[];
-
-
-
- for k=1:nz
-
- [xf,yf,zf] = nf3d(X(:,:,k),Y(:,:,k),Z(:,:,k));
-
- XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
-
- end
-
+ nx = 10; ny = 6; nz = 4;
+
+ x = linspace(0,2,nx);
+
+ y = linspace(0,1,ny);
+
+ z = linspace(0,0.5,nz);
+
+ [X,Y,Z] = ndgrid(x,y,z);
+
+ XF=[]; YF=[]; ZF=[];
+
+ for k=1:nz
+
+ [xf,yf,zf] = nf3d(X(:,:,k),Y(:,:,k),Z(:,:,k));
+
+ XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
+
+ end
+
+ for j=1:ny
+
+ [xf,yf,zf] = nf3d(matrix(X(:,j,:),[nx,nz]),...
+
+ matrix(Y(:,j,:),[nx,nz]),...
+
+ matrix(Z(:,j,:),[nx,nz]));
+
+ XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
+
+ end
+
+ plot3d(XF,YF,ZF, flag=[0 6 3], 66, 61, leg="X@Y@Z")
+
+ xtitle("A 3d grid !");
+
+ </scilab:image>
+
+ <para>
+ <emphasis role="bold">Example #3: Create a table of digrams:</emphasis>
+ </para>
+
+ <programlisting role="example"><![CDATA[
+[c1, c2] = ndgrid(["a" "b" "c"], ["a" "b" "c" "d" "e" "f" "g" "h"])
+c1+c2
+ ]]></programlisting>
+
+ <screen>
+
+ <![CDATA[--> [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 !
+]]>
+ </screen>
+
+</refsection>
+
+<refsection role="see also">
+
+ <title>参照</title>
+
+ <simplelist type="inline">
+
+ <member>
+ <link linkend="meshgrid">meshgrid</link>
- for j=1:ny
+ </member>
+
+ <member>
- [xf,yf,zf] = nf3d(matrix(X(:,j,:),[nx,nz]),...
+ <link linkend="kron">kron</link>
- matrix(Y(:,j,:),[nx,nz]),...
+ </member>
+
+ <member>
- matrix(Z(:,j,:),[nx,nz]));
+ <link linkend="feval">feval</link>
- XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
+ </member>
+
+ <member>
- end
+ <link linkend="eval3d">eval3d</link>
- plot3d(XF,YF,ZF, flag=[0 6 3], leg="X@Y@Z")
+ </member>
+
+ <member>
- xtitle("A 3d grid !");
+ <link linkend="nf3d">nf3d</link>
- </scilab:image>
+ </member>
- </refsection>
+ </simplelist>
- <refsection role="see also">
-
- <title>参照</title>
+</refsection>
+
+<refsection role="history">
+
+ <title>履歴</title>
+
+ <revhistory>
- <simplelist type="inline">
+ <revision>
- <member>
-
- <link linkend="kron">kron</link>
+ <revnumber>6.0</revnumber>
+
+ <revdescription>Extension to all homogeneous datatypes ([], booleans, encoded integers, polynomials, rationals, strings). Revision of the help page.
- </member>
+ </revdescription>
- </simplelist>
+ </revision>
- </refsection>
+ </revhistory>
-</refentry>
+</refsection>
+</refentry>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>\r
-<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="ja">\r
- <refnamediv>\r
- <refname>ndgrid</refname>\r
- <refpurpose>与えられたベクトルを複製することによって、行列またはN次元配列を作成\r
- </refpurpose>\r
- </refnamediv>\r
- <refsynopsisdiv>\r
- <title>呼び出し手順</title>\r
- <synopsis>[X, Y] = ndgrid(x,y)\r
- [X, Y, Z] = ndgrid(x,y,z)\r
- [X, Y, Z, T] = ndgrid(x,y,z,t)\r
- [X1, X2, ..., Xm] = ndgrid(x1,x2,...,xm)\r
- </synopsis>\r
- </refsynopsisdiv>\r
- <refsection role="arguments">\r
- <title>引数</title>\r
- <variablelist>\r
- <varlistentry>\r
- <term>x, y, z, ...</term>\r
- <listitem>\r
- <para>vectors of any data types. They may have distinct data types.</para>\r
- </listitem>\r
- </varlistentry>\r
- <varlistentry>\r
- <term>X, Y, Z, ...</term>\r
- <listitem>\r
- <para>\r
- 入力引数が2個の場合は行列,\r
- それ以外の場合はハイパー行列\r
- </para>\r
- </listitem>\r
- </varlistentry>\r
- </variablelist>\r
- </refsection>\r
- <refsection role="description">\r
- <title>説明</title>\r
- <para>The first application of <function>ndgrid</function> is to build\r
- a grid of nodes meshing the 2D or 3D or N-D space according to 2, 3,\r
- or more sets\r
- <literal>x</literal>, <literal> y</literal>, etc.. of \r
- "template" coordinates sampled along each direction/dimension of the\r
- space that you want to mesh.\r
- </para>\r
- <para>Hence, the matrix or hypermatrix <literal>X</literal> is made\r
- by replicating the vector <literal>x</literal> as all its columns ; \r
- the matrix or hypermatrix <literal>Y</literal> is made\r
- by replicating the vector <literal>y</literal> as all its rows ;\r
- <literal>Z</literal> is made of replicating the vector \r
- <literal>z</literal> along all its local thicknesses (3rd dimension); \r
- etc\r
- </para>\r
- <screen>\r
-<![CDATA[--> [X, Y] = ndgrid([1 3 4], [0 2 4 6])\r
- X = \r
- 1. 1. 1. 1.\r
- 3. 3. 3. 3.\r
- 4. 4. 4. 4.\r
-\r
- Y = \r
- 0. 2. 4. 6.\r
- 0. 2. 4. 6.\r
- 0. 2. 4. 6.\r
-]]></screen>\r
- <para> \r
- Then, the coordinates of the node(i,j) in the 2D space \r
- will be\r
- simply <literal>[x(i), y(j)]</literal> equal to \r
- <literal>[X(i,j), Y(i,j)]</literal>. As well, the coordinates of a\r
- <literal>node(i,j,k)</literal> of a 3D grid will be \r
- <literal>[x(i), y(j), z(k)]</literal> equal to \r
- <literal>[X(i,j,k), Y(i,j,k), Z(i,j,k)]</literal>.\r
- </para>\r
- <para>\r
- This replication scheme can be generalized to any number of dimensions,\r
- as well to any type of uniform data. Let's for instance consider 2\r
- attributes:\r
- <orderedlist>\r
- <listitem>The first is a number, to be chosen from the vector say\r
- <literal>n = [ 3 7 ]</literal>\r
- </listitem>\r
- <listitem>The second is a letter, to be chosen from the vector \r
- say <literal>c = ["a" "e" "i" "o" "u" "y"]</literal>\r
- </listitem>\r
- </orderedlist>\r
- Then we want to build the set of all {n,c} possible pairs. It will\r
- just be the 2D grid:\r
- </para>\r
- <screen>\r
-<![CDATA[--> [N, C] = ndgrid([3 7],["a" "e" "i" "o" "u" "y"])\r
- C = \r
-!a e i o u y !\r
-!a e i o u y !\r
-\r
- N = \r
- 3. 3. 3. 3. 3. 3.\r
- 7. 7. 7. 7. 7. 7.\r
-]]></screen>\r
- <para>Then, the object(i,j) will have the properties \r
- <literal>{n(i) c(j)}</literal> that now can be addressed with\r
- <literal>{N(i,j) C(i,j)}</literal>.\r
- This kind of grid may be useful to initialize an array of structures.\r
- </para>\r
- <para>Following examples show how to use <varname>X, Y, Z</varname> in\r
- most frequent applications.\r
- </para> \r
- </refsection>\r
- <refsection role="examples">\r
- <title>例</title>\r
-\r
- <para><emphasis role="bold">Example #1:</emphasis> </para>\r
- <programlisting role="example"><![CDATA[\r
-// Create a simple 2d grid\r
-x = linspace(-10,2,40);\r
-y = linspace(-5,5,40);\r
-[X,Y] = ndgrid(x,y);\r
-\r
-// Compute ordinates Z(X,Y) on the {X, Y} grid and plot Z(X,Y)\r
-Z = X - 3*X.*sin(X).*cos(Y-4) ;\r
-clf()\r
-plot3d(x,y,Z, flag=[color("green") 2 4], alpha=7, theta=60); show_window()\r
- ]]></programlisting>\r
- <scilab:image>\r
- x = linspace(-10,2,40);\r
- y = linspace(-5,5,40);\r
- [X,Y] = ndgrid(x,y);\r
- Z = X - 3*X.*sin(X).*cos(Y-4) ;\r
- clf()\r
- plot3d(x,y,Z, flag=[color("green") 2 4], alpha=7, theta=60); show_window()\r
- </scilab:image>\r
-\r
- <para><emphasis role="bold">Example #2:</emphasis> </para>\r
- <programlisting role="example"><![CDATA[\r
-// 簡単な3次元グリッドを作成\r
-nx = 10; ny = 6; nz = 4;\r
-x = linspace(0,2,nx);\r
-y = linspace(0,1,ny);\r
-z = linspace(0,0.5,nz);\r
-[X,Y,Z] = ndgrid(x,y,z);\r
-// 3次元グリッドを表示する ...\r
-XF=[]; YF=[]; ZF=[];\r
-for k=1:nz\r
- [xf,yf,zf] = nf3d(X(:,:,k),Y(:,:,k),Z(:,:,k));\r
- XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];\r
-end\r
-for j=1:ny\r
- [xf,yf,zf] = nf3d(matrix(X(:,j,:),[nx,nz]),...\r
- matrix(Y(:,j,:),[nx,nz]),...\r
- matrix(Z(:,j,:),[nx,nz]));\r
- XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];\r
-end\r
-clf()\r
-plot3d(XF,YF,ZF, flag=[0 6 3], 66, 61, leg="X@Y@Z")\r
-xtitle("A 3d grid !"); show_window()\r
- ]]></programlisting>\r
- <scilab:image>\r
- nx = 10; ny = 6; nz = 4;\r
- x = linspace(0,2,nx);\r
- y = linspace(0,1,ny);\r
- z = linspace(0,0.5,nz);\r
- [X,Y,Z] = ndgrid(x,y,z);\r
- XF=[]; YF=[]; ZF=[];\r
- for k=1:nz\r
- [xf,yf,zf] = nf3d(X(:,:,k),Y(:,:,k),Z(:,:,k));\r
- XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];\r
- end\r
- for j=1:ny\r
- [xf,yf,zf] = nf3d(matrix(X(:,j,:),[nx,nz]),...\r
- matrix(Y(:,j,:),[nx,nz]),...\r
- matrix(Z(:,j,:),[nx,nz]));\r
- XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];\r
- end\r
- plot3d(XF,YF,ZF, flag=[0 6 3], 66, 61, leg="X@Y@Z")\r
- xtitle("A 3d grid !");\r
- </scilab:image>\r
- <para><emphasis role="bold">Example #3: Create a table of digrams:</emphasis> </para>\r
- <programlisting role="example"><![CDATA[ \r
-[c1, c2] = ndgrid(["a" "b" "c"], ["a" "b" "c" "d" "e" "f" "g" "h"])\r
-c1+c2\r
- ]]></programlisting>\r
- <screen>\r
-<![CDATA[--> [c1, c2] = ndgrid(["a" "b" "c"], ["a" "b" "c" "d" "e" "f" "g" "h"])\r
- c2 = \r
-!a b c d e f g h !\r
-!a b c d e f g h !\r
-!a b c d e f g h !\r
-\r
- c1 = \r
-!a a a a a a a a !\r
-!b b b b b b b b !\r
-!c c c c c c c c !\r
-\r
---> c1+c2\r
- ans =\r
-!aa ab ac ad ae af ag ah !\r
-!ba bb bc bd be bf bg bh !\r
-!ca cb cc cd ce cf cg ch !\r
-]]></screen>\r
- </refsection>\r
- <refsection role="see also">\r
- <title>参照</title>\r
- <simplelist type="inline">\r
- <member>\r
- <link linkend="meshgrid">meshgrid</link>\r
- </member>\r
- <member>\r
- <link linkend="kron">kron</link>\r
- </member>\r
- <member>\r
- <link linkend="feval">feval</link>\r
- </member>\r
- <member>\r
- <link linkend="eval3d">eval3d</link>\r
- </member>\r
- <member>\r
- <link linkend="nf3d">nf3d</link>\r
- </member>\r
- </simplelist>\r
- </refsection>\r
- <refsection role="history">\r
- <title>履歴</title>\r
- <revhistory>\r
- <revision>\r
- <revnumber>6.0</revnumber>\r
- <revdescription>Extension to all homogeneous datatypes ([], booleans, encoded integers, polynomials, rationals, strings). Revision of the help page.\r
- </revdescription>\r
- </revision>\r
- </revhistory>\r
- </refsection>\r
-</refentry>
\ No newline at end of file
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<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="en">
- <refnamediv>
- <refname>ndgrid</refname>
- <refpurpose>Arrays para avaliação de função multidimensional em
- grid
- </refpurpose>
- </refnamediv>
- <refsynopsisdiv>
- <title>Seqüência de Chamamento</title>
- <synopsis>[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)
- </synopsis>
- </refsynopsisdiv>
- <refsection>
- <title>Parâmetros</title>
- <variablelist>
- <varlistentry>
- <term>x, y, z, ...</term>
- <listitem>
- <para>vetores </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term>X, Y, Z, ...</term>
+<?xml version="1.0" encoding="UTF-8"?>
+
+<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">
+
+<refnamediv>
+
+ <refname>ndgrid</refname>
+
+ <refpurpose>constrói matrizes ou matrizes N-D, replicando alguns vetores dadas
+
+ </refpurpose>
+
+</refnamediv>
+
+<refsynopsisdiv>
+
+ <title>Seqüência de Chamamento</title>
+
+ <synopsis>[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)
+
+ </synopsis>
+
+</refsynopsisdiv>
+
+<refsection role="arguments">
+
+ <title>Parâmetros</title>
+
+ <variablelist>
+
+ <varlistentry>
+
+ <term>x, y, z, ...</term>
+
+ <listitem>
+
+ <para>vetores de quaisquer tipos de dados.
+
+ Eles podem ter tipos de dados distintos.
+ </para>
+
+ </listitem>
+
+ </varlistentry>
+
+ <varlistentry>
+
+ <term>X, Y, Z, ...</term>
+
<listitem>
- <para>matrizes, no caso de 2 argumentos de entrada, ou hipermatrizes
- em outro caso
+
+ <para>matrices in case of 2 input arguments, or hypermatrices otherwise.
+
+ They all have the same sizes: size(x,"*") rows, size(x,"*") columns,
+
+ size(z,"*") layers, etc.
+
+ They have the datatypes of respective input vectors:
+
+ <literal>typeof(X)==typeof(x)</literal>,
+
+ <literal>typeof(Y)==typeof(y)</literal>, etc.
+
</para>
+
</listitem>
- </varlistentry>
- </variablelist>
- </refsection>
- <refsection>
- <title>Descrição</title>
- <para>Esta rotina utilitária é útil para criar arrays para a avaliação da
- função em grids 2, 3, ..., n dimensionais. Por exemplo, em 2d, um grid é
- definido por dois vetores, <literal>x</literal> e <literal> y</literal> de
- comprimento nx e ny, e se deseja avaliar uma função (dita f) em todos os
- pontos do grid, isto é, em todos os pontos de coordenadas (x(i),y(j)) com
- i=1,..,nx e j=1,..,ny . Neste caso, esta função pode computar as duas
- matrizes <literal>X,Y</literal> de tamanho nx x ny tais que :
- </para>
- <programlisting role=""><![CDATA[
- X(i,j) = x(i) para todo i em [1,nx]
- Y(i,j) = y(j) e j em [1,ny]
- ]]></programlisting>
- <para>
- e a avaliação pode ser feita com <literal>Z=f(X,Y)</literal> (sob a
- condição de que <literal>f</literal> foi codificada para a avaliação em
- argumentos de vetor, que é feito (em geral) usando os operadores elemento
- a elemento <literal>.*</literal>, <literal>./</literal> and
- <literal>.^</literal> no lugar de <literal>*</literal>,
- <literal>/</literal> e <literal>^</literal>).
- </para>
- <para>
- No caso 3d, considerando 3 vetores <literal>x,y,z</literal> de
- comprimentos nx, ny e nz, <literal>X,Y,Z</literal> são 3 hipermatrizes de
- tamanho nx x ny x nz tais que :
- </para>
- <programlisting role=""><![CDATA[
- X(i,j,k) = x(i)
- Y(i,j,k) = y(j) para todo (i,j,k) in [1,nx]x[1,ny]x[1,nz]
- Z(i,j,k) = z(k)
- ]]></programlisting>
- <para>
- No caso geral de m argumentos de entrada <literal>x1, x2, ..,
- xm
- </literal>
- ,os m argumentos de saída <literal>X1, X2, .., Xm</literal>
- são hipermatrizes de tamanho <emphasis>nx1 x nx2 x ... x nxm</emphasis> e
- :
- </para>
- <programlisting role=""><![CDATA[
- Xj(i1,i2,...,ij,...,im) = xj(ij)
- for all (i1,i2,...,im) in [1,nx1]x[1,nx2]x...x[1,nxm]
- ]]></programlisting>
- </refsection>
- <refsection>
- <title>Exemplos </title>
- <programlisting role="example"><![CDATA[
-// criando um grid 2d simples
-nx = 40; ny = 40;
-x = linspace(-1,1,nx);
-y = linspace(-1,1,ny);
+
+ </varlistentry>
+
+ </variablelist>
+
+</refsection>
+
+<refsection role="description">
+
+ <title>Descrição</title>
+
+ <para>
+ The first application of <function>ndgrid</function> is to build
+
+ a grid of nodes meshing the 2D or 3D or N-D space according to 2, 3,
+
+ or more sets
+
+ <literal>x</literal>, <literal> y</literal>, etc.. of
+
+ "template" coordinates sampled along each direction/dimension of the
+
+ space that you want to mesh.
+
+ </para>
+
+ <para>
+ Hence, the matrix or hypermatrix <literal>X</literal> is made
+
+ by replicating the vector <literal>x</literal> as all its columns;
+
+ the matrix or hypermatrix <literal>Y</literal> is made
+
+ by replicating the vector <literal>y</literal> as all its rows;
+
+ <literal>Z</literal> is made of replicating the vector
+
+ <literal>z</literal> along all its local thicknesses (3rd dimension);
+
+ etc
+
+ </para>
+
+ <screen>
+
+ <![CDATA[--> [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.
+]]>
+ </screen>
+
+ <para>
+
+ Then, the coordinates of the node(i,j) in the 2D space
+
+ will be
+
+ simply <literal>[x(i), y(j)]</literal> equal to
+
+ <literal>[X(i,j), Y(i,j)]</literal>. As well, the coordinates of a
+
+ <literal>node(i,j,k)</literal> of a 3D grid will be
+
+ <literal>[x(i), y(j), z(k)]</literal> equal to
+
+ <literal>[X(i,j,k), Y(i,j,k), Z(i,j,k)]</literal>.
+
+ </para>
+
+ <para>
+
+ 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:
+
+ <orderedlist>
+
+ <listitem>The first is a number, to be chosen from the vector say
+
+ <literal>n = [ 3 7 ]</literal>
+
+ </listitem>
+
+ <listitem>The second is a letter, to be chosen from the vector
+
+ say <literal>c = ["a" "e" "i" "o" "u" "y"]</literal>
+
+ </listitem>
+
+ </orderedlist>
+
+ Then we want to build the set of all {n,c} possible pairs. It will
+
+ just be the 2D grid:
+
+ </para>
+
+ <screen>
+
+ <![CDATA[--> [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.
+]]>
+ </screen>
+
+ <para>Then, the object(i,j) will have the properties
+
+ <literal>{n(i) c(j)}</literal> that now can be addressed with
+
+ <literal>{N(i,j) C(i,j)}</literal>.
+
+ This kind of grid may be useful to initialize an array of structures.
+
+ </para>
+
+ <para>
+ Following examples show how to use <varname>X, Y, Z</varname> in
+
+ most frequent applications.
+
+ </para>
+
+
+</refsection>
+
+<refsection role="examples">
+
+ <title>Exemplos </title>
+
+
+
+ <para>
+ <emphasis role="bold">Example #1:</emphasis>
+ </para>
+
+ <programlisting role="example"><![CDATA[
+// Criando um grid 2d simples
+x = linspace(-10,2,40);
+y = linspace(-5,5,40);
[X,Y] = ndgrid(x,y);
-// computando uma função no grid e plotando
-//deff("z=f(x,y)","z=128*x.^2 .*(1-x).^2 .*y.^2 .*(1-y).^2");
-deff("z=f(x,y)","z=x.^2 + y.^3")
-Z = f(X,Y);
+
+// Compute ordinates Z(X,Y) on the {X, Y} grid and plot Z(X,Y)
+Z = X - 3*X.*sin(X).*cos(Y-4) ;
clf()
-plot3d(x,y,Z, flag=[2 6 4]); show_window()
+plot3d(x,y,Z, flag=[color("green") 2 4], alpha=7, theta=60); show_window()
]]></programlisting>
- <scilab:image>
- nx = 40; ny = 40;
- x = linspace(-1,1,nx);
- y = linspace(-1,1,ny);
- [X,Y] = ndgrid(x,y);
- deff("z=f(x,y)","z=x.^2 + y.^3")
- Z = f(X,Y);
- plot3d(x,y,Z, flag=[2 6 4]);
- </scilab:image>
- <programlisting role="example"><![CDATA[
+
+ <scilab:image>
+
+ x = linspace(-10,2,40);
+
+ y = linspace(-5,5,40);
+
+ [X,Y] = ndgrid(x,y);
+
+ Z = X - 3*X.*sin(X).*cos(Y-4) ;
+
+ clf()
+
+ plot3d(x,y,Z, flag=[color("green") 2 4], alpha=7, theta=60); show_window()
+
+ </scilab:image>
+
+
+
+ <para>
+ <emphasis role="bold">Example #2:</emphasis>
+ </para>
+
+ <programlisting role="example"><![CDATA[
// criando um grid 3d simples
nx = 10; ny = 6; nz = 4;
x = linspace(0,2,nx);
XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
end
clf()
-plot3d(XF,YF,ZF, flag=[0 6 3], leg="X@Y@Z")
+plot3d(XF,YF,ZF, flag=[0 6 3], 66, 61, leg="X@Y@Z")
xtitle("A 3d grid !"); show_window()
- ]]></programlisting>
- <scilab:image>
- nx = 10; ny = 6; nz = 4;
- x = linspace(0,2,nx);
- y = linspace(0,1,ny);
- z = linspace(0,0.5,nz);
- [X,Y,Z] = ndgrid(x,y,z);
-
- XF=[]; YF=[]; ZF=[];
-
- for k=1:nz
- [xf,yf,zf] = nf3d(X(:,:,k),Y(:,:,k),Z(:,:,k));
- XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
- end
-
- for j=1:ny
- [xf,yf,zf] = nf3d(matrix(X(:,j,:),[nx,nz]),...
- matrix(Y(:,j,:),[nx,nz]),...
- matrix(Z(:,j,:),[nx,nz]));
- XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
- end
- plot3d(XF,YF,ZF, flag=[0 6 3], leg="X@Y@Z")
- xtitle("A 3d grid !");
- </scilab:image>
- </refsection>
- <refsection role="see also">
- <title>Ver Também</title>
- <simplelist type="inline">
- <member>
- <link linkend="kron">kron</link>
- </member>
- </simplelist>
- </refsection>
+ ]]> </programlisting>
+
+ <scilab:image>
+
+ nx = 10; ny = 6; nz = 4;
+
+ x = linspace(0,2,nx);
+
+ y = linspace(0,1,ny);
+
+ z = linspace(0,0.5,nz);
+
+ [X,Y,Z] = ndgrid(x,y,z);
+
+
+
+ XF=[]; YF=[]; ZF=[];
+
+
+
+ for k=1:nz
+
+ [xf,yf,zf] = nf3d(X(:,:,k),Y(:,:,k),Z(:,:,k));
+
+ XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
+
+ end
+
+
+
+ for j=1:ny
+
+ [xf,yf,zf] = nf3d(matrix(X(:,j,:),[nx,nz]),...
+
+ matrix(Y(:,j,:),[nx,nz]),...
+
+ matrix(Z(:,j,:),[nx,nz]));
+
+ XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
+
+ end
+
+ plot3d(XF,YF,ZF, flag=[0 6 3], 66, 61, leg="X@Y@Z")
+
+ xtitle("A 3d grid !");
+
+ </scilab:image>
+
+
+
+ <para>
+ <emphasis role="bold">Example #3: Create a table of digrams:</emphasis>
+ </para>
+
+ <programlisting role="example"><![CDATA[
+[c1, c2] = ndgrid(["a" "b" "c"], ["a" "b" "c" "d" "e" "f" "g" "h"])
+c1+c2
+ ]]> </programlisting>
+
+ <screen>
+
+ <![CDATA[--> [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 !
+]]>
+ </screen>
+
+
+
+</refsection>
+
+<refsection role="see also">
+
+ <title>Ver Também</title>
+
+ <simplelist type="inline">
+
+ <member>
+
+ <link linkend="meshgrid">meshgrid</link>
+
+ </member>
+
+ <member>
+
+ <link linkend="kron">kron</link>
+
+ </member>
+
+ <member>
+
+ <link linkend="feval">feval</link>
+
+ </member>
+
+ <member>
+
+ <link linkend="eval3d">eval3d</link>
+
+ </member>
+
+ <member>
+
+ <link linkend="nf3d">nf3d</link>
+
+ </member>
+
+ </simplelist>
+
+</refsection>
+
+<refsection role="history">
+
+ <title>Histórico</title>
+
+ <revhistory>
+
+ <revision>
+
+ <revnumber>6.0</revnumber>
+
+ <revdescription>Extension to all homogeneous datatypes ([], booleans, encoded integers,
+ polynomials, rationals, strings). Revision of the help page.
+
+ </revdescription>
+
+ </revision>
+
+ </revhistory>
+
+</refsection>
+
</refentry>
+
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>\r
-<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
- <refnamediv>\r
- <refname>ndgrid</refname>\r
- <refpurpose>constrói matrizes ou matrizes N-D, replicando alguns vetores dadas\r
- </refpurpose>\r
- </refnamediv>\r
- <refsynopsisdiv>\r
- <title>Seqüência de Chamamento</title>\r
- <synopsis>[X, Y] = ndgrid(x,y)\r
- [X, Y, Z] = ndgrid(x,y,z)\r
- [X, Y, Z, T] = ndgrid(x,y,z,t)\r
- [X1, X2, ..., Xm] = ndgrid(x1,x2,...,xm)\r
- </synopsis>\r
- </refsynopsisdiv>\r
- <refsection role="arguments">\r
- <title>Parâmetros</title>\r
- <variablelist>\r
- <varlistentry>\r
- <term>x, y, z, ...</term>\r
- <listitem>\r
- <para>vetores de quaisquer tipos de dados. \r
- Eles podem ter tipos de dados distintos.</para>\r
- </listitem>\r
- </varlistentry>\r
- <varlistentry>\r
- <term>X, Y, Z, ...</term>\r
- <listitem>\r
- <para>matrizes, no caso de 2 argumentos de entrada, ou hipermatrizes\r
- em outro caso \r
- </para>\r
- </listitem>\r
- </varlistentry>\r
- </variablelist>\r
- </refsection>\r
- <refsection role="description">\r
- <title>Descrição</title>\r
- <para>The first application of <function>ndgrid</function> is to build\r
- a grid of nodes meshing the 2D or 3D or N-D space according to 2, 3,\r
- or more sets\r
- <literal>x</literal>, <literal> y</literal>, etc.. of \r
- "template" coordinates sampled along each direction/dimension of the\r
- space that you want to mesh.\r
- </para>\r
- <para>Hence, the matrix or hypermatrix <literal>X</literal> is made\r
- by replicating the vector <literal>x</literal> as all its columns ; \r
- the matrix or hypermatrix <literal>Y</literal> is made\r
- by replicating the vector <literal>y</literal> as all its rows ;\r
- <literal>Z</literal> is made of replicating the vector \r
- <literal>z</literal> along all its local thicknesses (3rd dimension); \r
- etc\r
- </para>\r
- <screen>\r
-<![CDATA[--> [X, Y] = ndgrid([1 3 4], [0 2 4 6])\r
- X = \r
- 1. 1. 1. 1.\r
- 3. 3. 3. 3.\r
- 4. 4. 4. 4.\r
-\r
- Y = \r
- 0. 2. 4. 6.\r
- 0. 2. 4. 6.\r
- 0. 2. 4. 6.\r
-]]></screen>\r
- <para> \r
- Then, the coordinates of the node(i,j) in the 2D space \r
- will be\r
- simply <literal>[x(i), y(j)]</literal> equal to \r
- <literal>[X(i,j), Y(i,j)]</literal>. As well, the coordinates of a\r
- <literal>node(i,j,k)</literal> of a 3D grid will be \r
- <literal>[x(i), y(j), z(k)]</literal> equal to \r
- <literal>[X(i,j,k), Y(i,j,k), Z(i,j,k)]</literal>.\r
- </para>\r
- <para>\r
- This replication scheme can be generalized to any number of dimensions,\r
- as well to any type of uniform data. Let's for instance consider 2\r
- attributes:\r
- <orderedlist>\r
- <listitem>The first is a number, to be chosen from the vector say\r
- <literal>n = [ 3 7 ]</literal>\r
- </listitem>\r
- <listitem>The second is a letter, to be chosen from the vector \r
- say <literal>c = ["a" "e" "i" "o" "u" "y"]</literal>\r
- </listitem>\r
- </orderedlist>\r
- Then we want to build the set of all {n,c} possible pairs. It will\r
- just be the 2D grid:\r
- </para>\r
- <screen>\r
-<![CDATA[--> [N, C] = ndgrid([3 7],["a" "e" "i" "o" "u" "y"])\r
- C = \r
-!a e i o u y !\r
-!a e i o u y !\r
-\r
- N = \r
- 3. 3. 3. 3. 3. 3.\r
- 7. 7. 7. 7. 7. 7.\r
-]]></screen>\r
- <para>Then, the object(i,j) will have the properties \r
- <literal>{n(i) c(j)}</literal> that now can be addressed with\r
- <literal>{N(i,j) C(i,j)}</literal>.\r
- This kind of grid may be useful to initialize an array of structures.\r
- </para>\r
- <para>Following examples show how to use <varname>X, Y, Z</varname> in\r
- most frequent applications.\r
- </para> \r
- </refsection>\r
- <refsection role="examples">\r
- <title>Exemplos </title>\r
- \r
- <para><emphasis role="bold">Example #1:</emphasis> </para>\r
- <programlisting role="example"><![CDATA[ \r
-// Criando um grid 2d simples\r
-x = linspace(-10,2,40);\r
-y = linspace(-5,5,40);\r
-[X,Y] = ndgrid(x,y);\r
-\r
-// Compute ordinates Z(X,Y) on the {X, Y} grid and plot Z(X,Y)\r
-Z = X - 3*X.*sin(X).*cos(Y-4) ;\r
-clf()\r
-plot3d(x,y,Z, flag=[color("green") 2 4], alpha=7, theta=60); show_window()\r
- ]]></programlisting>\r
- <scilab:image>\r
- x = linspace(-10,2,40);\r
- y = linspace(-5,5,40);\r
- [X,Y] = ndgrid(x,y);\r
- Z = X - 3*X.*sin(X).*cos(Y-4) ;\r
- clf()\r
- plot3d(x,y,Z, flag=[color("green") 2 4], alpha=7, theta=60); show_window()\r
- </scilab:image>\r
- \r
- <para><emphasis role="bold">Example #2:</emphasis> </para>\r
- <programlisting role="example"><![CDATA[ \r
-// criando um grid 3d simples\r
-nx = 10; ny = 6; nz = 4;\r
-x = linspace(0,2,nx);\r
-y = linspace(0,1,ny);\r
-z = linspace(0,0.5,nz);\r
-[X,Y,Z] = ndgrid(x,y,z);\r
-// tente exibir este grid 3d...\r
-XF=[]; YF=[]; ZF=[];\r
-for k=1:nz\r
- [xf,yf,zf] = nf3d(X(:,:,k),Y(:,:,k),Z(:,:,k));\r
- XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];\r
-end\r
-for j=1:ny\r
- [xf,yf,zf] = nf3d(matrix(X(:,j,:),[nx,nz]),...\r
- matrix(Y(:,j,:),[nx,nz]),...\r
- matrix(Z(:,j,:),[nx,nz]));\r
- XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];\r
-end\r
-clf()\r
-plot3d(XF,YF,ZF, flag=[0 6 3], 66, 61, leg="X@Y@Z")\r
-xtitle("A 3d grid !"); show_window()\r
- ]]> </programlisting>\r
- <scilab:image>\r
- nx = 10; ny = 6; nz = 4;\r
- x = linspace(0,2,nx);\r
- y = linspace(0,1,ny);\r
- z = linspace(0,0.5,nz);\r
- [X,Y,Z] = ndgrid(x,y,z);\r
- \r
- XF=[]; YF=[]; ZF=[];\r
- \r
- for k=1:nz\r
- [xf,yf,zf] = nf3d(X(:,:,k),Y(:,:,k),Z(:,:,k));\r
- XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];\r
- end\r
- \r
- for j=1:ny\r
- [xf,yf,zf] = nf3d(matrix(X(:,j,:),[nx,nz]),...\r
- matrix(Y(:,j,:),[nx,nz]),...\r
- matrix(Z(:,j,:),[nx,nz]));\r
- XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];\r
- end\r
- plot3d(XF,YF,ZF, flag=[0 6 3], 66, 61, leg="X@Y@Z")\r
- xtitle("A 3d grid !"); \r
- </scilab:image>\r
-\r
- <para><emphasis role="bold">Example #3: Create a table of digrams:</emphasis> </para>\r
- <programlisting role="example"><![CDATA[ \r
-[c1, c2] = ndgrid(["a" "b" "c"], ["a" "b" "c" "d" "e" "f" "g" "h"])\r
-c1+c2\r
- ]]> </programlisting>\r
- <screen>\r
-<![CDATA[--> [c1, c2] = ndgrid(["a" "b" "c"], ["a" "b" "c" "d" "e" "f" "g" "h"])\r
- c2 = \r
-!a b c d e f g h !\r
-!a b c d e f g h !\r
-!a b c d e f g h !\r
-\r
- c1 = \r
-!a a a a a a a a !\r
-!b b b b b b b b !\r
-!c c c c c c c c !\r
-\r
---> c1+c2\r
- ans =\r
-!aa ab ac ad ae af ag ah !\r
-!ba bb bc bd be bf bg bh !\r
-!ca cb cc cd ce cf cg ch !\r
-]]></screen>\r
-\r
- </refsection>\r
- <refsection role="see also">\r
- <title>Ver Também</title>\r
- <simplelist type="inline">\r
- <member>\r
- <link linkend="meshgrid">meshgrid</link>\r
- </member>\r
- <member>\r
- <link linkend="kron">kron</link>\r
- </member>\r
- <member>\r
- <link linkend="feval">feval</link>\r
- </member>\r
- <member>\r
- <link linkend="eval3d">eval3d</link>\r
- </member>\r
- <member>\r
- <link linkend="nf3d">nf3d</link>\r
- </member>\r
- </simplelist>\r
- </refsection>\r
- <refsection role="history">\r
- <title>Histórico</title>\r
- <revhistory>\r
- <revision>\r
- <revnumber>6.0</revnumber>\r
- <revdescription>Extension to all homogeneous datatypes ([], booleans, encoded integers, polynomials, rationals, strings). Revision of the help page.\r
- </revdescription>\r
- </revision>\r
- </revhistory>\r
- </refsection>\r
-</refentry>\r
<?xml version="1.0" encoding="UTF-8"?>
+
<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">
- <refnamediv>
- <refname>ndgrid</refname>
- <refpurpose>
- массивы для многомерного вычисления функций по координатной сетке
- </refpurpose>
- </refnamediv>
- <refsynopsisdiv>
- <title>Последовательность вызова</title>
- <synopsis>
- 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)
- </synopsis>
- </refsynopsisdiv>
- <refsection>
- <title>Аргументы</title>
- <variablelist>
- <varlistentry>
- <term>x, y, z, ...</term>
- <listitem>
- <para>векторы</para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term>X, Y, Z, ...</term>
+
+<refnamediv>
+
+ <refname>ndgrid</refname>
+
+ <refpurpose>строит матриц или N-мерные массивы путем репликации данных векторов
+
+ </refpurpose>
+
+</refnamediv>
+
+<refsynopsisdiv>
+
+ <title>Последовательность вызова</title>
+
+ <synopsis>
+
+ 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)
+
+ </synopsis>
+
+</refsynopsisdiv>
+
+<refsection role="arguments">
+
+ <title>Аргументы</title>
+
+ <variablelist>
+
+ <varlistentry>
+
+ <term>x, y, z, ...</term>
+
+ <listitem>
+
+ <para>векторы любых типов данных. Они могут иметь различные типы данных.</para>
+
+ </listitem>
+
+ </varlistentry>
+
+ <varlistentry>
+
+ <term>X, Y, Z, ...</term>
+
<listitem>
- <para>
- в случае двух входных аргументов - матрицы, в противном случае - гиперматрицы
+
+ <para>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.
+ </para>
+ <para>
+
+ They have the datatypes of respective input vectors:
+
+ <literal>typeof(X)==typeof(x)</literal>,
+
+ <literal>typeof(Y)==typeof(y)</literal>, etc.
+
</para>
+
</listitem>
- </varlistentry>
- </variablelist>
- </refsection>
- <refsection>
- <title>Описание</title>
- <para>
- Эта служебная программа полезна для создания массивов для вычисления функций по 2-х, 3-х, ... , n-мерной координатной сетке. Например, в двухмерная координатная сетка определяется двумя векторами, <literal>x</literal> и <literal>y</literal> длиной <literal>nx</literal> и <literal>ny</literal> и вы хотите вычислить функцию (скажем, <emphasis>f</emphasis>) во всех точках координатной сетки, то есть во всех точках с координатами <emphasis>(x(i),y(j))</emphasis>, где <emphasis>i=1,..,nx</emphasis> и <emphasis>j=1,..,ny</emphasis>. В этом случае данная функция может вычислить две матрицы <literal>X,Y</literal> размером <emphasis>nx x ny</emphasis> такие, что:
- </para>
- <screen><![CDATA[
-X(i,j) = x(i) для всех i в [1,nx]
-Y(i,j) = y(j) и j в [1,ny]
- ]]></screen>
- <para>
- и вычисление может быть сделано с <literal>Z=f(X,Y)</literal> (при условии, что вы написали код функции <literal>f</literal> для работы с векторными аргументами, что делается (вообще) с помощью поэлементных операторов <literal>.*</literal>, <literal>./</literal> и <literal>.^</literal> вместо <literal>*</literal>, <literal>/</literal> и <literal>^</literal>).
- </para>
- <para>
- В трёхмерном случае, рассматриваются три вектора <literal>x, y, z</literal> длиной <literal>nx</literal>, <literal>ny</literal> и <literal>nz</literal>. <literal>X, Y, Z</literal> являются тремя гиперматрицами размерами <emphasis>nx x ny x nz</emphasis> такими, что:
- </para>
- <screen><![CDATA[
-X(i,j,k) = x(i)
-Y(i,j,k) = y(j) для всех (i,j,k) в [1,nx] x [1,ny] x [1,nz]
-Z(i,j,k) = z(k)
- ]]></screen>
- <para>
- В общем случае <literal>m</literal> входных аргументов <literal>x1, x2, ... , xm</literal>, тогда <literal>m</literal> выходных аргументов <literal>X1, X2, ... , Xm</literal> являются гиперматрицами размерами <emphasis>nx1 x nx2 x ... x nxm</emphasis> и:
- </para>
- <screen><![CDATA[
-Xj(i1,i2,...,ij,...,im) = xj(ij)
-для всех (i1,i2,...,im) в [1,nx1] x [1,nx2] x ... x [1,nxm]
- ]]></screen>
- </refsection>
- <refsection>
- <title>Примеры</title>
- <programlisting role="example"><![CDATA[
+
+ </varlistentry>
+
+ </variablelist>
+
+</refsection>
+
+<refsection role="description">
+
+ <title>Описание</title>
+
+ <para>
+ The first application of <function>ndgrid</function> is to build
+
+ a grid of nodes meshing the 2D or 3D or N-D space according to 2, 3,
+
+ or more sets
+
+ <literal>x</literal>, <literal> y</literal>, etc.. of
+
+ "template" coordinates sampled along each direction/dimension of the
+
+ space that you want to mesh.
+
+ </para>
+
+ <para>
+ Hence, the matrix or hypermatrix <literal>X</literal> is made
+
+ by replicating the vector <literal>x</literal> as all its columns;
+
+ the matrix or hypermatrix <literal>Y</literal> is made
+
+ by replicating the vector <literal>y</literal> as all its rows;
+
+ <literal>Z</literal> is made of replicating the vector
+
+ <literal>z</literal> along all its local thicknesses (3rd dimension);
+
+ etc
+
+ </para>
+
+ <screen>
+
+ <![CDATA[--> [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.
+]]>
+ </screen>
+
+ <para>
+
+ 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:
+
+ <orderedlist>
+
+ <listitem>The first is a number, to be chosen from the vector say
+
+ <literal>n = [ 3 7 ]</literal>
+
+ </listitem>
+
+ <listitem>The second is a letter, to be chosen from the vector
+
+ say <literal>c = ["a" "e" "i" "o" "u" "y"]</literal>
+
+ </listitem>
+
+ </orderedlist>
+
+ Then we want to build the set of all {n,c} possible pairs. It will
+
+ just be the 2D grid:
+
+ </para>
+
+ <screen>
+
+ <![CDATA[--> [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.
+]]>
+ </screen>
+
+ <para>Then, the object(i,j) will have the properties
+
+ <literal>{n(i) c(j)}</literal> that now can be addressed with
+
+ <literal>{N(i,j) C(i,j)}</literal>.
+
+ This kind of grid may be useful to initialize an array of structures.
+
+ </para>
+
+ <para>
+ Following examples show how to use <varname>X, Y, Z</varname> in
+
+ most frequent applications.
+
+ </para>
+
+
+</refsection>
+
+<refsection role="examples">
+
+ <title>Примеры</title>
+
+
+
+ <para>
+ <emphasis role="bold">Example #1:</emphasis>
+ </para>
+
+ <programlisting role="example"><![CDATA[
// создание простой двухмерной координатной сетки
-nx = 40; ny = 40;
-x = linspace(-1,1,nx);
-y = linspace(-1,1,ny);
+x = linspace(-10,2,40);
+y = linspace(-5,5,40);
[X,Y] = ndgrid(x,y);
-
-// вычисление функции в координатной сетке и построение её на графике
-deff("z=f(x,y)","z=x.^2 + y.^3")
-Z = f(X,Y);
+
+// Compute ordinates Z(X,Y) on the {X, Y} grid and plot Z(X,Y)
+Z = X - 3*X.*sin(X).*cos(Y-4) ;
clf()
-plot3d(x,y,Z, flag=[2 6 4]); show_window()
- ]]></programlisting>
- <scilab:image>
- nx = 40; ny = 40;
- x = linspace(-1,1,nx);
- y = linspace(-1,1,ny);
- [X,Y] = ndgrid(x,y);
- deff("z=f(x,y)","z=x.^2 + y.^3")
- Z = f(X,Y);
- plot3d(x,y,Z, flag=[2 6 4]);
- </scilab:image>
- <programlisting role="example"><![CDATA[
+plot3d(x,y,Z, flag=[color("green") 2 4], alpha=7, theta=60); show_window()
+ ]]> </programlisting>
+
+ <scilab:image>
+
+ x = linspace(-10,2,40);
+
+ y = linspace(-5,5,40);
+
+ [X,Y] = ndgrid(x,y);
+
+ Z = X - 3*X.*sin(X).*cos(Y-4) ;
+
+ clf()
+
+ plot3d(x,y,Z, flag=[color("green") 2 4], alpha=7, theta=60); show_window()
+
+ </scilab:image>
+
+
+
+ <para>
+ <emphasis role="bold">Example #2:</emphasis>
+ </para>
+
+ <programlisting role="example"><![CDATA[
// создание простой трёхмерной координатной сетки
nx = 10; ny = 6; nz = 4;
x = linspace(0,2,nx);
end
clf()
-plot3d(XF,YF,ZF, flag=[0 6 3], leg="X@Y@Z")
+plot3d(XF,YF,ZF, flag=[0 6 3], 66, 61, leg="X@Y@Z")
xtitle("Трёхмерная сетка!"); show_window()
]]></programlisting>
- <scilab:image localized="true">
- nx = 10; ny = 6; nz = 4;
- x = linspace(0,2,nx);
- y = linspace(0,1,ny);
- z = linspace(0,0.5,nz);
- [X,Y,Z] = ndgrid(x,y,z);
-
- XF=[]; YF=[]; ZF=[];
-
- for k=1:nz
- [xf,yf,zf] = nf3d(X(:,:,k), Y(:,:,k), Z(:,:,k));
- XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
- end
-
- for j=1:ny
- [xf,yf,zf] = nf3d(matrix(X(:,j,:),[nx,nz]),..
- matrix(Y(:,j,:),[nx,nz]),..
- matrix(Z(:,j,:),[nx,nz]));
- XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
- end
-
- clf()
- plot3d(XF,YF,ZF, flag=[0 6 3], leg="X@Y@Z")
- xtitle("Трёхмерная сетка!"); show_window()
-
- </scilab:image>
- </refsection>
- <refsection role="see also">
- <title>Смотрите также</title>
- <simplelist type="inline">
- <member>
- <link linkend="kron">kron</link>
- </member>
- </simplelist>
- </refsection>
+
+ <scilab:image localized="true">
+
+ nx = 10; ny = 6; nz = 4;
+
+ x = linspace(0,2,nx);
+
+ y = linspace(0,1,ny);
+
+ z = linspace(0,0.5,nz);
+
+ [X,Y,Z] = ndgrid(x,y,z);
+
+
+
+ XF=[]; YF=[]; ZF=[];
+
+
+
+ for k=1:nz
+
+ [xf,yf,zf] = nf3d(X(:,:,k), Y(:,:,k), Z(:,:,k));
+
+ XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
+
+ end
+
+
+
+ for j=1:ny
+
+ [xf,yf,zf] = nf3d(matrix(X(:,j,:),[nx,nz]),..
+
+ matrix(Y(:,j,:),[nx,nz]),..
+
+ matrix(Z(:,j,:),[nx,nz]));
+
+ XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf];
+
+ end
+
+
+
+ clf()
+
+ plot3d(XF,YF,ZF, flag=[0 6 3], 66, 61, leg="X@Y@Z")
+
+ xtitle("Трёхмерная сетка!"); show_window()
+
+
+
+ </scilab:image>
+
+
+
+ <para>
+ <emphasis role="bold">Example #3: Create a table of digrams:</emphasis>
+ </para>
+
+ <programlisting role="example"><![CDATA[
+[c1, c2] = ndgrid(["a" "b" "c"], ["a" "b" "c" "d" "e" "f" "g" "h"])
+c1+c2
+ ]]> </programlisting>
+
+ <screen>
+
+ <![CDATA[--> [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 !
+]]>
+ </screen>
+
+
+
+</refsection>
+
+<refsection role="see also">
+
+ <title>Смотрите также</title>
+
+ <simplelist type="inline">
+
+ <member>
+
+ <link linkend="meshgrid">meshgrid</link>
+
+ </member>
+
+ <member>
+
+ <link linkend="kron">kron</link>
+
+ </member>
+
+ <member>
+
+ <link linkend="feval">feval</link>
+
+ </member>
+
+ <member>
+
+ <link linkend="eval3d">eval3d</link>
+
+ </member>
+
+ <member>
+
+ <link linkend="nf3d">nf3d</link>
+
+ </member>
+
+ </simplelist>
+
+</refsection>
+
+<refsection role="history">
+
+ <title>История</title>
+
+ <revhistory>
+
+ <revision>
+
+ <revnumber>6.0</revnumber>
+
+ <revdescription>Extension to all homogeneous datatypes ([], booleans, encoded integers, polynomials, rationals, strings). Revision of the help page.
+
+ </revdescription>
+
+ </revision>
+
+ </revhistory>
+
+</refsection>
+
</refentry>
+