<?xml version="1.0" encoding="UTF-8"?>
<!--
 * Scilab ( https://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:ns3="http://www.w3.org/1999/xhtml"
          xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org"
          xml:id="sum" xml:lang="pt">
    <refnamediv>
        <refname>sum</refname>
        <refpurpose>soma (soma linha, soma coluna) de entradas de um vetor ou
            matriz
        </refpurpose>
    </refnamediv>
    <refsynopsisdiv>
        <title>Seqüência de Chamamento</title>
        <synopsis>
            y = sum(x)
            y = sum(x, outtype)
            y = sum(x, orientation)
            y = sum(x, orientation, outtype)
        </synopsis>
    </refsynopsisdiv>
    <refsection>
        <title>Parâmetros</title>
        <variablelist>
            <varlistentry>
                <term>x</term>
                <listitem>
                    Matriz ou hypermatriz de booleanos (densa ou esparsa), números inteiros codificados,
                    números reais ou complexos (densa ou esparsa), polinômios ou racionais.
                    <para/>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>orientation</term>
                <listitem>
                    it can be either
                    <itemizedlist>
                        <listitem>
                            a character <literal>"*"</literal> (default), <literal>"r"</literal>,
                          <literal>"c"</literal> or  <literal>"m"</literal>
                        </listitem>
                        <listitem>
                            a positive integer: Index of the dimension along which the sums must be computed.
                        </listitem>
                    </itemizedlist>
                    <para/>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>outtype</term>
                <listitem>
                    string <literal>"native"</literal> or <literal>"double"</literal>.
                    <para/>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>y</term>
                <listitem>
                    escalar ou vetor
                    <para/>
                </listitem>
            </varlistentry>
        </variablelist>
    </refsection>
    <refsection>
        <title>Descrição</title>
        <para>
            Para um vetor ou matriz <literal>x</literal>,
            <literal>y=sum(x)</literal> retorna no escalar <literal>y</literal> a soma
            de todas as entradas de <literal>x</literal>.
        </para>
        <para>
            <literal>y=sum(x,'r')</literal> (ou, equivalentemente,
            <literal>y=sum(x,1)</literal>) é a soma linha a linha:: <literal>y(j)=
                sum(x(:,j))
            </literal>
            .<literal>y</literal> é um vetor linha.
        </para>
        <para>
            <literal>y=sum(x,'c')</literal> (ou, equivalentemente,
            <literal>y=sum(x,2)</literal>) é a soma coluna a coluna. Retorna em cada
            entrada do vetor coluna <literal>y</literal> a soma : <literal>y(i)=
                sum(x(i,:))
            </literal>
            )).
        </para>
        <para>
            <literal>y=sum(x,'m')</literal> é a soma ao longo da primeira
            dimensão "não-singleton" de <literal>x</literal> (para compatibilidade com
            Matlab).
        </para>
    </refsection>
    <refsection>
        <title>Exemplos</title>
        <programlisting role="example"><![CDATA[
A = [1,2 ; 3,4];
sum(A)
sum(A,1)

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

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

B = [%t %t %f %f];
sum(B) //evaluation in float
sum(B, "native") //similar to or(B)
 ]]></programlisting>
    </refsection>
    <refsection role="see also">
        <title>Ver Também</title>
        <simplelist type="inline">
            <member>
                <link linkend="plus">plus</link>
            </member>
            <member>
                <link linkend="cumsum">cumsum</link>
            </member>
            <member>
                <link linkend="prod">prod</link>
            </member>
        </simplelist>
    </refsection>
</refentry>
