16dc1001b835a916efc3d03e10bb4f8dcba214e3
[scilab.git] / scilab / modules / elementary_functions / help / en_US / matrixoperations / cumsum.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!--
3  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4  * Copyright (C) 2010 - Serge Steer - INRIA
5  *
6  * Copyright (C) 2012 - 2016 - Scilab Enterprises
7  *
8  * This file is hereby licensed under the terms of the GNU GPL v2.0,
9  * pursuant to article 5.3.4 of the CeCILL v.2.1.
10  * This file was originally licensed under the terms of the CeCILL v2.1,
11  * and continues to be available under such terms.
12  * For more information, see the COPYING file which you should have received
13  * along with this program.
14  *
15  -->
16 <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" xml:id="cumsum">
17     <refnamediv>
18         <refname>cumsum</refname>
19         <refpurpose>cumulative sum of array elements</refpurpose>
20     </refnamediv>
21     <refsynopsisdiv>
22         <title>Syntax</title>
23         <synopsis>y=cumsum(x)
24             y=cumsum(x,orientation)
25             y=cumsum(x,outtype)
26             y=cumsum(x,orientation,outtype)
27         </synopsis>
28     </refsynopsisdiv>
29
30     <refsection role="parameters">
31         <title>Arguments</title>
32         <variablelist>
33             <varlistentry>
34                 <term>x</term>
35                 <listitem>
36                     <para>an array of reals, complex, booleans, polynomials or rational fractions.</para>
37                 </listitem>
38             </varlistentry>
39             <varlistentry>
40                 <term>orientation</term>
41                 <listitem>
42                     <para>This argument can be</para>
43                     <itemizedlist>
44                         <listitem>
45                             <para>
46                                 either a string with possible values <literal>"*"</literal>, <literal>"r"</literal>, <literal>"c"</literal> or <literal>"m"</literal>
47                             </para>
48                         </listitem>
49                         <listitem>
50                             <para>or a number with positive integer value</para>
51                         </listitem>
52                     </itemizedlist>
53                 </listitem>
54             </varlistentry>
55             <varlistentry>
56                 <term>outtype</term>
57                 <listitem>
58                     <para>
59                         a string with possible values <literal>"native"</literal> or <literal>"double"</literal>.
60                     </para>
61                 </listitem>
62             </varlistentry>
63             <varlistentry>
64                 <term>y</term>
65                 <listitem>
66                     <para>scalar or array</para>
67                 </listitem>
68             </varlistentry>
69         </variablelist>
70     </refsection>
71
72     <refsection role="description">
73         <title>Description</title>
74         <para>
75             Returns the cumulative sum of array elements.
76             For an array <term>x</term>, <literal>y=cumsum(x)</literal> a matrix <term>y</term> of the same size as <term>x</term>.
77             The value <literal>y(i)</literal> is the sum of all elements of <literal>x(1:i)</literal> <emphasis role="italic">i.e.</emphasis>:
78         </para>
79         <para>
80             <latex><![CDATA[ y(i) = \sum_{k=1}^i x(k)]]></latex>
81         </para>
82         <para>
83             <literal>y=cumsum(x,orientation)</literal> returns in <term>y</term> the cumulative sum of <term>x</term> along the dimension given by <term>orientation</term>:
84         </para>
85         <itemizedlist>
86             <listitem>
87                 <para>
88                     if <term>orientation</term> is equal to 1 or "r" then:
89                 </para>
90                 <para>
91                     <latex><![CDATA[ y(\mathbf{l},j) = \sum_{\mathbf{i}=1}^l x(\mathbf{i},j)]]></latex>
92                 </para>
93                 <para>or </para>
94                 <para>
95                     <latex><![CDATA[ y(\mathbf{l},j,k,\ldots) = \sum_{\mathbf{i}=1}^l x(\mathbf{i},j,k,\ldots)]]></latex>
96                 </para>
97             </listitem>
98             <listitem>
99                 <para>
100                     if <term>orientation</term> is equal to 2 or "c" then:
101                 </para>
102                 <para>
103                     <latex><![CDATA[ y(i,\mathbf{l}) = \sum_{\mathbf{j}=1}^l x(i,{\mathbf{j})]]></latex>
104                 </para>
105                 <para> or </para>
106                 <para>
107                     <latex><![CDATA[ y(i,\mathbf{l},k,\ldots) = \sum_{\mathbf{j}=1}^l x(i,\mathbf{j},k,\ldots)]]></latex>
108                 </para>
109             </listitem>
110             <listitem>
111                 <para>
112                     if <term>orientation</term> is equal to n then:
113                 </para>
114                 <para>
115                     <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>
116                 </para>
117             </listitem>
118             <listitem>
119                 <para>
120                     <literal>y=cumsum(x,"*")</literal> is equivalent to <literal>y=cumsum(x)</literal>
121                 </para>
122             </listitem>
123             <listitem>
124                 <para>
125                     <literal>y=cumsum(x,"m")</literal> 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.
126                 </para>
127             </listitem>
128         </itemizedlist>
129         <para/>
130         <para>
131             The <term>outtype</term> argument rules the way the summation is done:
132         </para>
133         <itemizedlist>
134             <listitem>
135                 <para>
136                     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.
137                 </para>
138             </listitem>
139             <listitem>
140                 <para>For arrays of integers,</para>
141                 <para>
142                     if <literal>outtype="native"</literal> the evaluation is done using integer computations (modulo 2^b, where b is the number of bits used),
143                 </para>
144                 <para>
145                     if <literal>outtype="double"</literal> the evaluation is done using floating point computations.
146                 </para>
147                 <para>
148                     The default value is <literal>outtype="native"</literal>.
149                 </para>
150             </listitem>
151             <listitem>
152                 <para>For arrays of booleans,</para>
153                 <para>
154                     if <literal>outtype="native"</literal> the evaluation is done using boolean computations ( + is replaced by |),
155                 </para>
156                 <para>
157                     if <literal>outtype="double"</literal> the evaluation is done using floating point computations (%t values are replaced by 1 and %f values by 0).
158                 </para>
159                 <para>
160                     The default value is <literal>outtype="double"</literal>.
161                 </para>
162             </listitem>
163         </itemizedlist>
164         <note>
165             This function applies, with identical rules to <link linkend="sparse">sparse matrices</link>.
166         </note>
167     </refsection>
168
169     <refsection role="examples">
170         <title>Examples</title>
171         <programlisting role="example"><![CDATA[
172 A=[1,2;3,4];
173 cumsum(A)
174 cumsum(A,1)
175
176 I=uint8([2 95 103;254 9 0])
177 cumsum(I) //native evaluation
178 cumsum(I,"double")
179 cumsum(I,2,"double")
180
181 s=poly(0,"s");
182 P=[s,%i+s;s^2,1];
183 cumsum(P),
184 cumsum(P,2)
185
186 B=[%t %t %f %f];
187 cumsum(B) //evaluation in float
188 cumsum(B,"native") //similar to or(B)
189  ]]></programlisting>
190     </refsection>
191
192     <refsection role="see also">
193         <title>See also</title>
194         <simplelist type="inline">
195             <member>
196                 <link linkend="sum">sum</link>
197             </member>
198             <member>
199                 <link linkend="cumprod">cumprod</link>
200             </member>
201         </simplelist>
202     </refsection>
203 </refentry>