<?xml version="1.0" encoding="UTF-8"?>
<!--
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 * Copyright (C) 2008 - INRIA
 *
 * Copyright (C) 2012 - 2016 - Scilab Enterprises
 *
 * This file is hereby licensed under the terms of the GNU GPL v2.0,
 * pursuant to article 5.3.4 of the CeCILL v.2.1.
 * This file was originally licensed under the terms of the CeCILL v2.1,
 * and continues to be available under such terms.
 * For more information, see the COPYING file which you should have received
 * along with this program.
 *
 -->
<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:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org"
          xml:id="cumsum" xml:lang="pt">

    <refnamediv>
        <refname>cumsum</refname>
        <refpurpose>somas cumulativas parciais dos elementos de uma matriz</refpurpose>
    </refnamediv>

    <refsynopsisdiv>
        <title>Seqüência de Chamamento</title>
        <synopsis>
            y = cumsum(x)
            y = cumsum(x, 'r') or y = cumsum(x, 1)
            y = cumsum(x, 'c') or y = cumsum(x, 2)
            y = cumsum(x, orientation)
            y = cumsum(.., outtype)
        </synopsis>
    </refsynopsisdiv>

    <refsection role="parameters">
        <title>Parâmetros</title>
        <variablelist>
            <varlistentry>
                <term>x</term>
                <listitem>
                    <para>
                        vetor ou matriz de booleanos, inteiros, números reais ou complexos,
                        polinômios ou frações racionais.
                        Hipermatrizes ou matrizes booleanas ou numéricas esparsas também são suportadas.
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>"r", "c", 1, 2,.. orientation</term>
                <listitem>
                    <para>This argument can be</para>
                    <itemizedlist>
                        <listitem>
                            <para>
                                either a string with possible values <literal>"*"</literal>,
                                <literal>"r"</literal>, <literal>"c"</literal> or <literal>"m"</literal>
                            </para>
                        </listitem>
                        <listitem>
                            <para>
                              positive integer 1 ≤ orientation ≤ ndims(x): the index of the
                              dimension along which the partial cumulative sums must be computed.
                              1 and "r", and 2 and "c", are equivalent.
                            </para>
                        </listitem>
                    </itemizedlist>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>outtype</term>
                <listitem>
                    <para>
                        Word <literal>"native"</literal> or <literal>"double"</literal>.
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>y</term>
                <listitem>
                    <para>Array de tamanho igual ao de <varname>x</varname>.</para>
                </listitem>
            </varlistentry>
        </variablelist>
    </refsection>

    <refsection role="description">
        <title>Descrição</title>
        <para>
            <emphasis role="bold">y = cumsum(x)</emphasis> calcula e fornece o parcial
            somas cumulativas <literal>y(i) = sum(x(1:i))</literal> :
        </para>
        <para>
            <latex alt="y(i) = ∑u=1→i x(u)"><![CDATA[ y(i) = \sum_{u=1}^i x(u)]]></latex>
        </para>
        <para>
            <emphasis role="bold">y = cumsum(x, orientation)</emphasis> retorna retorna o parcial
             somas cumulativas de <term>x</term> ao longo da dimensão dada pela <term>orientation</term> :
        </para>
        <para>
            <itemizedlist>
                <listitem>
                    <para>
                        Se <term>orientation</term> for igual a 1 ou "r", então
                    </para>
                    <para>
                        <latex alt="y(i,j) = ∑u=1→i x(u,j)"><![CDATA[
                            y(\mathbf{i},j) = \sum_{u=1}^{\mathbf{i}} x(\mathbf{u},j)   ]]>
                        </latex>, ou para uma matriz N-Dimensional :
                    </para>
                    <para>
                        <latex alt="y(i,j,k,…) = ∑u=1→i x(u,j,k,…)"><![CDATA[
                            y(\mathbf{i},j,k,\ldots) = \sum_{u=1}^{\mathbf{i}} x(\mathbf{u},j,k,\ldots)  ]]>
                        </latex>
                    </para>
                </listitem>
                <listitem>
                    <para>
                        Se <term>orientation</term> for igual a 2 ou "c", então
                    </para>
                    <para>
                        <latex alt="y(i,j) = ∑u=1→j x(i,u)"><![CDATA[
                            y(i,\mathbf{j}) = \sum_{u=1}^{\mathbf{j}} x(i,{\mathbf{u})  ]]>
                        </latex>, ou para uma matriz N-Dimensional :
                    </para>
                    <para>
                        <latex alt="y(i,j,k,…) = ∑u=1→j x(i,u,k,…)"><![CDATA[
                            y(i,\mathbf{j},k,\ldots) = \sum_{u=1}^{\mathbf{j}} x(i,\mathbf{u},k,\ldots) ]]>
                        </latex>
                    </para>
                </listitem>
                <listitem>
                    <para>
                        Se <term>orientation</term> for igual a n, então
                    </para>
                    <para>
                        <latex alt="y(i₁,…,iₙ₋₁, iₙ,iₙ₊₁,…) = ∑u=1…iₙ  x(i₁,…,iₙ₋₁, u,iₙ₊₁,…)"><![CDATA[
                            y(i_1,\ldots,i_{n-1},\mathbf{i_{n}},i_{n+1},\ldots) =
                            \sum_{u=1}^{\mathbf{i_n}} x(i_1,\ldots,i_{n-1},\mathbf{u},i_{n+1},\ldots) ]]>
                        </latex>
                    </para>
                </listitem>
                <listitem>
                    <para>
                        <emphasis role="bold">y = cumsum(x,"*")</emphasis> is equivalent to
                        <literal>y = cumsum(x)</literal>
                    </para>
                </listitem>
                <listitem>
                    <para>
                        <emphasis role="bold">y = cumsum(x,"m")</emphasis> is equivalent to
                        <literal>y = cumsum(x, orientation)</literal> where <term>orientation</term>
                        is the index of the first dimension of <term>x</term> that is greater than 1.
                        This option is used for Matlab compatibility.
                    </para>
                </listitem>
            </itemizedlist>
        </para>
        <para>
            The <term>outtype</term> argument rules the way the summations are done:
        </para>
        <itemizedlist>
            <listitem>
                <para>
                    For arrays of floats, of polynomials, of rational fractions, the evaluation
                    is always done using floating points computations. The <literal>"double"</literal>
                    or <literal>"native"</literal> options are equivalent.
                </para>
            </listitem>
            <listitem>
                <para>For arrays of integers,</para>
                <para>
                    if <literal>outtype="native"</literal> the evaluation is done using integer
                    computations (modulo 2^b, where b is the number of bits used),
                </para>
                <para>
                    if <literal>outtype="double"</literal> the evaluation is done using floating
                    point computations.
                </para>
                <para>
                    The default value is <literal>outtype="native"</literal>.
                </para>
            </listitem>
            <listitem>
                <para>For arrays of booleans,</para>
                <para>
                    if <literal>outtype="native"</literal> the evaluation is done using boolean
                    computations ( + is replaced by |),
                </para>
                <para>
                    if <literal>outtype="double"</literal> the evaluation is done using floating
                    point computations (%t values are replaced by 1 and %f values by 0).
                </para>
                <para>
                    The default value is <literal>outtype="double"</literal>.
                </para>
            </listitem>
        </itemizedlist>
        <warning>
            When the input <varname>x</varname> is sparse, please keep in mind that the density
            of the result <varname>y</varname> will be almost always close to 100%.
        </warning>
    </refsection>

    <refsection role="examples">
        <title>Exemplos</title>
        <programlisting role="example"><![CDATA[
A = [1,2;3,4];
cumsum(A)
cumsum(A,1)

I = uint8([2 95 103 ; 254 9 0])
cumsum(I) // native evaluation
cumsum(I,"double")
cumsum(I,2,"double")

s = poly(0,"s");
P = [s, %i+s ; s^2 , 1];
cumsum(P)
cumsum(P, 2)

B = [%t %t %f %f];
cumsum(B)          // evaluation in float
cumsum(B,"native") // similar to or(B)
     ]]></programlisting>
    </refsection>

    <refsection role="see also">
        <title>Ver Também</title>
        <simplelist type="inline">
            <member>
                <link linkend="sum">sum</link>
            </member>
            <member>
                <link linkend="cumprod">cumprod</link>
            </member>
        </simplelist>
    </refsection>

</refentry>
