<?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:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="cumsum" xml:lang="pt">

    <refnamediv>
        <refname>cumsum</refname>
        <refpurpose>soma cumulativa</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)
        </synopsis>
    </refsynopsisdiv>

    <refsection role="parameters">
        <title>Parâmetros</title>
        <variablelist>
            <varlistentry>
                <term>x</term>
                <listitem>
                    <para>vetor ou matrix (de reais ou complexos) </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>y</term>
                <listitem>
                    <para>vetor ou matrix (de reais ou complexos)</para>
                </listitem>
            </varlistentry>
        </variablelist>
    </refsection>

    <refsection role="description">
        <title>Descrição</title>
        <para>
            Para um vetor ou uma matriz <term>x</term>,
            <literal>y=cumsum(x)</literal> retorna em <term>y</term> a soma
            cumulativa de todas as entradas de <term>x</term> tomadas coluna a
            coluna.
        </para>
        <para>
            <latex><![CDATA[ y(i) = \sum_{k=1}^i x(k)]]></latex>
        </para>
        <para>
            <literal>y=cumsum(x,'r')</literal> (ou, equivalentemente,
            <literal>y=cumsum(x,1)</literal>) retorna em <literal>y</literal> a soma
            cumulativa das linhas de <term>x</term>: <literal>
                y(:,i)=cumsum(x(:,i))
            </literal>
        </para>
        <para>
            <latex><![CDATA[ y(\mathbf{l},j) = \sum_{\mathbf{i}=1}^l x(\mathbf{i},j)]]></latex>
        </para>
        <para>or </para>
        <para>
            <latex><![CDATA[ y(\mathbf{l},j,k,\ldots) = \sum_{\mathbf{i}=1}^l x(\mathbf{i},j,k,\ldots)]]></latex>
        </para>
        <para>
            <literal>y=cumsum(x,'c')</literal> (ou, equivalentemente,
            <literal>y=cumsum(x,2)</literal>) retorna em <term>y</term> a soma
            cumulativa das colunas de <term>x</term>: <literal>
                y(i,:)=cumsum(x(i,:))
            </literal>
        </para>
        <para>
            <latex><![CDATA[ y(i,\mathbf{l}) = \sum_{\mathbf{j}=1}^l x(i,{\mathbf{j})]]></latex>
        </para>
        <para> or </para>
        <para>
            <latex><![CDATA[ y(i,\mathbf{l},k,\ldots) = \sum_{\mathbf{j}=1}^l x(i,\mathbf{j},k,\ldots)]]></latex>
        </para>
        <para>
            if <term>orientation</term> is equal to n then:
        </para>
        <para>
            <latex><![CDATA[ y(i_1,\ldots,i_{n-1},\mathbf{l},i_{n+1},\ldots) = \sum_{\mathbf{i_n}=1}^l x(i_1,\ldots,i_{n-1},\mathbf{i_n},i_{n+1},\ldots)]]></latex>
        </para>
        <para>
            <literal>y=cumsum(x,"*")</literal> is equivalent to <literal>y=cumsum(x)</literal>
        </para>
        <para>
            <literal>y=cumsum(x,'m')</literal> é a soma cumulativa ao longo da
            primeira dimensão "não-singleton" de <term>x</term> (para
            compatibilidade com o Matlab).
        </para>
        <para>
            The <term>outtype</term> argument rules the way the summation is 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>
        <note>
            This function applies, with identical rules to <link linkend="sparse">sparse matrices</link>.
        </note>
    </refsection>

    <refsection role="examples">
        <title>Exemplos</title>
        <programlisting role="example"><![CDATA[
A=[1,2;3,4];
cumsum(A)
cumsum(A,'r')
cumsum(A,'c')
a=rand(3,4)+%i;
[m,n]=size(a);
w=zeros(a);
w(1,:)=a(1,:);
for k=2:m;w(k,:)=w(k-1,:)+a(k,:);end;w-cumsum(a,'r')
 ]]></programlisting>
    </refsection>

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

</refentry>
