-<?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>
+