2.53 sum all rows in a matrix
Given the folowing 2D matrix \(A\) find the sum of each row
\[ \begin {pmatrix} 1 & 2 & 3\\ 4 & 5 & 6\\ 7 & 8 & 9 \end {pmatrix} \]
2.53.1 Mathematica
mat={{1,2,3},
{4,5,6},
{7,8,9}}
Total[mat,{2}]
|
Out[2]= {6,
15,
24}
|
2.53.2 Matlab
A=[1 2 3;4 5 6;7 8 9];
sum(A,2)
|
ans =
6
15
24
|
2.53.3 Maple
A:=Matrix([[1,2,3],[4,5,6],[7,8,9]]);
map(x->add(x),convert(A,listlist))
#or may be better is
`add`~([LinearAlgebra:-Row(A,[1..-1])])
|
[6, 15, 24]
|