I have a matrix in Mathematica:
W = {{Subscript[x, 11], Subscript[x, 12], Subscript[x, 13]},
{Subscript[x, 21], Subscript[x, 22], Subscript[x, 23]},
{Subscript[x, 31], Subscript[x, 32], Subscript[x, 33]}}
I would like to make a column vector (called g
), where each row (i.e. each element) is the sum of the equivalent row in the matrix W
.
My code for g
is, at the moment:
g = {{Total[W[[1]]]}, {Total[W[[2]]]}, {Total[W[[3]]]}}
This is fine for this situation, where the matrix W
only has a few rows. But if matrix W
were giant, this wouldn't be a great approach, as I would need to index every single row in the matrix when defining g
.
I'm new to Mathematica, so I thought that the answer might involve the Do
function, for a matrix with a total of A
rows...
Do[Subscript[g, i] = Total[W[[i]],{1,A}]
...but this doesn't seem to solve the issue.
I would be very grateful if anyone could point me in the right direction. I am sure this is a very simple question for all you Mathematica whizzes... ;)