|
We're glad you came by, but you might find what you're looking for elsewhere. TI-Basic Developer is not the site it once was. While its information on commands and other calculator features remains almost second-to-none, its forum, archives, and even hosting service, Wikidot, have been decaying for years. The calculator community would love to see what you're working on, or help you in your next coding adventure, but TI-Basic Developer is no longer the place to do it. Instead, you should head over to Cemetech (primarily American) or TI-Planet (primarily international). Both are active, well-established forums with their own archives, chatrooms, reference material, and abundant coding tools and resources. We'll see you there, we hope. |
Returns the sum of the elements of a matrix.
[A] - the matrix whose elements you want to sum
Ans - the sum of the matrix elements
[A], L₁, Ans
TI-83/84/+/SE
zada
URL: United TI
:dim([A]
:Matr►list(cumSum([A])T,Ans(1),L₁
:sum(L₁
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.
.