<< signm Matrix operations tril >>

Scilab Help >> Elementary Functions > Matrix operations > sum

sum

sum of array elements

Syntax

y=sum(x)
y=sum(x,orientation)
y=sum(x,outtype)
y=sum(x,orientation,outtype)

Arguments

x

an array of reals, complex, booleans, polynomials or rational fractions.

orientation

it can be either

  • a string with possible values "*", "r", "c" or "m"

  • a number with positive integer value

outtype

a string with possible values "native" or "double".

y

scalar or array

Description

For an array x, y=sum(x) returns in the scalar y the sum of all the elements of x.

y=sum(x,orientation) returns in y the sum of x along the dimension given by orientation:

The outtype argument rules the way the summation is done:

This function applies with identical rules to sparse matrices

Examples

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)

See also


Report an issue
<< signm Matrix operations tril >>