Re: Re: Adding elements of a matrix
- To: mathgroup at smc.vnet.net
- Subject: [mg40663] Re: [mg40601] Re: Adding elements of a matrix
- From: Dr Bob <majort at cox-internet.com>
- Date: Sat, 12 Apr 2003 03:12:32 -0400 (EDT)
- References: <b738oh$o7l$1@smc.vnet.net> <200304110559.BAA01881@smc.vnet.net>
- Reply-to: majort at cox-internet.com
- Sender: owner-wri-mathgroup at wolfram.com
The original requirement: >> i have a matrix m[[i,j]] and i want to add every term where >> i<j (this is to avoiding adding twice the same number) This solution isn't better than others, but perhaps it introduces a couple of useful techniques. It is only for square matrices. << LinearAlgebra`MatrixManipulation` upper[n_Integer] := UpperDiagonalMatrix[1 &, n] - IdentityMatrix[n] upper[m_?SquareMatrixQ] := m*upper@Length@m sumUpper[m_?SquareMatrixQ] := Plus @@ Flatten@upper[m] m=Table[a[i,j],{i,3},{j,3}]; sumUpper@m a[1, 2] + a[1, 3] + a[2, 3] Bobby On Fri, 11 Apr 2003 01:59:25 -0400 (EDT), Jens-Peer Kuska <kuska at informatik.uni-leipzig.de> wrote: > Hi, > > m = Table[a[i, j], {i, 3}, {j, 3}]; > summand = Table[b[i, j], {i, 3}, {j, 3}]; > > and > > MapIndexed[ > If[Greater @@ #2, #1 + Part[summand, Sequence @@ #2], #1] &, m, {2}] > > will increment only the upper triangular part. > > Regards > Jens > > Rebeca Choy wrote: >> >> Hi, >> >> How can I add in Mathematica every element of a matrix without adding >> twice the mixed terms? >> >> for example i have a matrix m[[i,j]] and i want to add every term where >> i<j (this is to avoiding adding twice the same number) >> >> Can I do it with Sum? >> >> Rebeca Choy > > -- majort at cox-internet.com Bobby R. Treat
- References:
- Re: Adding elements of a matrix
- From: Jens-Peer Kuska <kuska@informatik.uni-leipzig.de>
- Re: Adding elements of a matrix