help-octave
[Top][All Lists]

## RE: sum() behaving erratically?

 From: Ciotti, Louis A Subject: RE: sum() behaving erratically? Date: Thu, 7 Oct 2004 08:37:40 -0400

```Assuming that sum is suppose to behaive like matlab(according to matlab
documentation):

B = sum(A) returns sums along different dimensions of an array.

If A is a vector, sum(A) returns the sum of the elements.

If A is a matrix, sum(A) treats the columns of A as vectors, returning a
row vector of the sums of each column.

If A is a multidimensional array, sum(A) treats the values along the
first non-singleton dimension as vectors, returning an array of row
vectors.

B = sum(A,dim) sums along the dimension of A specified by scalar dim.

This leads me to believe that sum is working correctly.

-----Original Message-----
Sent: Wednesday, October 06, 2004 9:46 PM
Subject: Re: sum() behaving erratically?

I'm using Octave 2.1.46 and get the same results.
octave:9> help sum
sum is a built-in function
- Built-in Function:  sum (X, DIM)
Sum of elements along dimension DIM.  If DIM is omitted, it
defaults to 1 (column-wise sum).
Therefore I'd expect for a=[1,2];
that sum(a) should be the same as sum (a,1)  = 1 2 and as stated below.
Henry

> I'm a bit embarrassed to ask this, but here goes:
>
> If I let a=[1,2;3,4]; and then ask for sum(a), sum(a,1) and sum(a,2),
I
>
> 4 6     4 6     3
>               7
>
> respectively. Now I let a=[1,2]; and do the same. I now get
>
> 3       1 2     3
>
> indicating that in the second case sum(a) != sum(a,1), in direct
violation
> of the documentation in the manual. Is this supposed to be like this
and
> didn't I understand things, or is it a bug? (Octave is 2.1.57.)
>
>
> Kind regards,
> Maarten
>
>
>
> -------------------------------------------------------------
> Octave is freely available under the terms of the GNU GPL.
>
> Octave's home on the web:  http://www.octave.org
> How to fund new projects:  http://www.octave.org/funding.html
> Subscription information:  http://www.octave.org/archive.html
> -------------------------------------------------------------
>

-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------

-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------

```