13
13
<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">
15
<refname>cumsum</refname>
16
<refpurpose>cumulative sum of array elements</refpurpose>
19
<title>Calling Sequence</title>
20
<synopsis>y=cumsum(x)</synopsis>
21
<synopsis>y=cumsum(x,orientation)</synopsis>
22
<synopsis>y=cumsum(x,outtype)</synopsis>
23
<synopsis>y=cumsum(x,orientation,outtype)</synopsis>
26
<title>Arguments</title>
31
<para>an array of reals, complex, booleans, polynomials or rational fractions.</para>
35
<term>orientation</term>
37
<para>This argument can be</para>
41
either a string with possible values <literal>"*"</literal>, <literal>"r"</literal>, <literal>"c"</literal> or <literal>"m"</literal>
45
<para>or a number with positive integer value</para>
54
a string with possible values <literal>"native"</literal> or <literal>"double"</literal>.
61
<para>scalar or array</para>
67
<title>Description</title>
69
For an array <literal>x</literal>, <literal>y=cumsum(x)</literal> returns in the scalar <literal>y</literal> the cumulative sum of all the elements of <literal>x</literal>.
72
<literal>y=cumsum(x,orientation)</literal> returns in <literal>y</literal> the cumulative sum of <literal>x</literal> along the dimension given by <literal>orientation</literal>:
77
if <literal>orientation</literal> is equal to 1 or "r" then:
80
<latex><![CDATA[ y(\mathbf{l},j) = \sum_{\mathbf{i}=1}^l x(\mathbf{i},j)]]></latex>
84
<latex><![CDATA[ y(\mathbf{l},j,k,\ldots) = \sum_{\mathbf{i}=1}^l x(\mathbf{i},j,k,\ldots)]]></latex>
89
if <literal>orientation</literal> is equal to 2 or "c" then:
92
<latex><![CDATA[ y(i,\mathbf{l}) = \sum_{\mathbf{j}=1}^l x(i,{\mathbf{j})]]></latex>
96
<latex><![CDATA[ y(i,\mathbf{l},k,\ldots) = \sum_{\mathbf{j}=1}^l x(i,\mathbf{j},k,\ldots)]]></latex>
101
if <literal>orientation</literal> is equal to n then:
104
<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>
109
<literal>y=cumsum(x,"*")</literal> is equivalent to <literal>y=cumsum(x)</literal>
114
<literal>y=cumsum(x,"m")</literal> is equivalent to <literal>y=cumsum(x,orientation)</literal> where <literal>orientation</literal> is the index of the first dimension of <literal>x</literal> that is greater than 1. This option is used for Matlab compatibility.
120
The <literal>outtype</literal> argument rules the way the summation is done:
125
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.
129
<para>For arrays of integers,</para>
131
if <literal>outtype="native"</literal> the evaluation is done using integer computations (modulo 2^b, where b is the number of bits used),
134
if <literal>outtype="double"</literal> the evaluation is done using floating point computations.
137
The default value is <literal>outtype="native"</literal>.
141
<para>For arrays of booleans,</para>
143
if <literal>outtype="native"</literal> the evaluation is done using boolean computations ( + is replaced by |),
146
if <literal>outtype="double"</literal> the evaluation is done using floating point computations (%t values are replaced by 1 and %f values by 0).
149
The default value is <literal>outtype="double"</literal>.
155
<title>Remark</title>
157
This function applies, with identical rules to <link linkend="sparse">sparse matrices</link> and <link linkend="hypermat">hypermatrices</link>.
161
<title>Examples</title>
162
<programlisting role="example"><![CDATA[
15
<refname>cumsum</refname>
16
<refpurpose>cumulative sum of array elements</refpurpose>
19
<title>Calling Sequence</title>
20
<synopsis>y=cumsum(x)</synopsis>
21
<synopsis>y=cumsum(x,orientation)</synopsis>
22
<synopsis>y=cumsum(x,outtype)</synopsis>
23
<synopsis>y=cumsum(x,orientation,outtype)</synopsis>
26
<title>Arguments</title>
31
<para>an array of reals, complex, booleans, polynomials or rational fractions.</para>
35
<term>orientation</term>
37
<para>This argument can be</para>
41
either a string with possible values <literal>"*"</literal>, <literal>"r"</literal>, <literal>"c"</literal> or <literal>"m"</literal>
45
<para>or a number with positive integer value</para>
54
a string with possible values <literal>"native"</literal> or <literal>"double"</literal>.
61
<para>scalar or array</para>
67
<title>Description</title>
69
For an array <literal>x</literal>, <literal>y=cumsum(x)</literal> returns in the scalar <literal>y</literal> the cumulative sum of all the elements of <literal>x</literal>.
72
<literal>y=cumsum(x,orientation)</literal> returns in <literal>y</literal> the cumulative sum of <literal>x</literal> along the dimension given by <literal>orientation</literal>:
77
if <literal>orientation</literal> is equal to 1 or "r" then:
80
<latex><![CDATA[ y(\mathbf{l},j) = \sum_{\mathbf{i}=1}^l x(\mathbf{i},j)]]></latex>
84
<latex><![CDATA[ y(\mathbf{l},j,k,\ldots) = \sum_{\mathbf{i}=1}^l x(\mathbf{i},j,k,\ldots)]]></latex>
89
if <literal>orientation</literal> is equal to 2 or "c" then:
92
<latex><![CDATA[ y(i,\mathbf{l}) = \sum_{\mathbf{j}=1}^l x(i,{\mathbf{j})]]></latex>
96
<latex><![CDATA[ y(i,\mathbf{l},k,\ldots) = \sum_{\mathbf{j}=1}^l x(i,\mathbf{j},k,\ldots)]]></latex>
101
if <literal>orientation</literal> is equal to n then:
104
<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>
109
<literal>y=cumsum(x,"*")</literal> is equivalent to <literal>y=cumsum(x)</literal>
114
<literal>y=cumsum(x,"m")</literal> is equivalent to <literal>y=cumsum(x,orientation)</literal> where <literal>orientation</literal> is the index of the first dimension of <literal>x</literal> that is greater than 1. This option is used for Matlab compatibility.
120
The <literal>outtype</literal> argument rules the way the summation is done:
125
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.
129
<para>For arrays of integers,</para>
131
if <literal>outtype="native"</literal> the evaluation is done using integer computations (modulo 2^b, where b is the number of bits used),
134
if <literal>outtype="double"</literal> the evaluation is done using floating point computations.
137
The default value is <literal>outtype="native"</literal>.
141
<para>For arrays of booleans,</para>
143
if <literal>outtype="native"</literal> the evaluation is done using boolean computations ( + is replaced by |),
146
if <literal>outtype="double"</literal> the evaluation is done using floating point computations (%t values are replaced by 1 and %f values by 0).
149
The default value is <literal>outtype="double"</literal>.
155
<title>Remark</title>
157
This function applies, with identical rules to <link linkend="sparse">sparse matrices</link> and <link linkend="hypermat">hypermatrices</link>.
161
<title>Examples</title>
162
<programlisting role="example"><![CDATA[