Sum of Matrix Elements

Routine Summary

Returns the sum of the elements of a matrix.

Inputs

[A] - the matrix whose elements you want to sum

Outputs

Ans - the sum of the matrix elements

Variables Used

[A], L₁, Ans

Calculator Compatibility

TI-83/84/+/SE

Author

zada

URL: United TI

Download

sumofmatrix.zip

:dim([A]
:Matr►list(cumSum([A])T,Ans(1),L1
:sum(L1

The cumSum( command gets the cumulative sum of each column in the matrix, adding the value of the previous element to the next element, and repeating this for each consecutive element in the column. When the cumSum( command is finished, the last element in each column will contain the sum of that column. Taking the T (transpose) of the resulting matrix switches columns and rows.

Then, using the Matr►list( command, the last column of this result is stored to L₁. This column was originally the last row of cumSum('s output, so it contains all the column sums. Finally, by calculating the sum of that list, we get the total of the matrix elements. L₁ is no longer necessary, and can be deleted.

If you want to use the sum for future use, you can store it to a more permanent variable, such as A or X. When you are done using [A], you should clean it up at the end of your program.

.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License