home *** CD-ROM | disk | FTP | other *** search
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * *
- * Copyright (c) 1997 MathSoft, Inc. All Rights Reserved. *
- * *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
- /*
- * Function: sum ( x )
- *
- * Description:
- * sum(x) returns the sum of each column of x.
- * For a vector, sum(x) returns the sum of the elements of x.
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
- function sum ( x )
-
- r=rows(x);
- c=cols(x);
-
- sum = new(c);
-
- if (r == 1) // row vector (or scalar) case
-
- sum = x;
-
- elseif (c == 1) // column vector case
-
- for i in 0:(r-1)
- sum = sum + x[i] ;
- end
-
- else // array case
-
- for i in 0:(r-1)
- for j in 0:(c-1)
- sum[i] = sum[i] + x[j;i] ;
- end
- end
-
- end
-
- end