The Museum of HP Calculators

HP Forum Archive 17

[ Return to Index | Top of Index ]

Is there a command to total all matrix elements?
Message #1 Posted by Reuben on 23 Feb 2007, 8:54 p.m.

I've got a 5x6 matrix and I need to add all the elements together. I didn't want to have to decompile the matrix and perform '+' 29 times though. I've looked in the matrix section in the user guide a few times, and can't find anything that will do this.

Thanks in advance! --Reuben

      
Re: Is there a command to total all matrix elements?
Message #2 Posted by allen on 23 Feb 2007, 11:24 p.m.,
in response to message #1 by Reuben

(Revised from earlier post)

You could just take the dot product with unity matrix:

 
[[ 1 2 3 ]      [[1 1 1]
 [ 4 5 6 ]  dot  [1 1 1]  = 45 
 [ 7 8 9 ]]      [1 1 1]]
which is 1+2+3+4+5+6+7+8+9=45

Edited: 24 Feb 2007, 10:19 a.m.

            
Re: Is there a command to total all matrix elements?
Message #3 Posted by John Keith on 25 Feb 2007, 7:49 p.m.,
in response to message #2 by allen

A little longer but faster:

OBJ-> OBJ-> DROP * ->LIST \Sigma\LIST

John

                  
Re: Is there a command to total all matrix elements?
Message #4 Posted by allen on 26 Feb 2007, 8:25 p.m.,
in response to message #3 by John Keith

John, Right you are, your method is at least twice as fast as the method I posted above. My original response was much closer to your objobj method, but I revised it because it did not address the question.

Reuben's question had "opportunities for learning" in programming (trying to sum a list by +,+,+,+,+,+,+) and in mathematics (not knowing that the DOT product already does sum the elements in a vector/matrix). So I thought it more fitting to address only the mathematics issue, hoping that he would take some initiave and figure out the rest. (e.g. a simpler, faster, better... way)

Edited: 26 Feb 2007, 11:49 p.m.

      
<<DUP SIZE 1 CON DOT>> AKA soup in a Vietnamese Restraunt
Message #5 Posted by allen on 25 Feb 2007, 12:28 a.m.,
in response to message #1 by Reuben

 <<
      DUP SIZE 1 CON DOT
      >> 

(If you say it outloud to yourself it sounds very much like ordering soup in a Vietnamese Restraunt!) :-)

Edited: 25 Feb 2007, 12:32 a.m.


[ Return to Index | Top of Index ]

Go back to the main exhibit hall