Difference between revisions of "TI-BASIC:Sum Of Matrix"
(Automated @@ correction) |
(Automated internal link correction) |
||
(One intermediate revision by the same user not shown) | |||
Line 14: | Line 14: | ||
{{Template:TI-BASIC:Prgm-code | {{Template:TI-BASIC:Prgm-code | ||
|code=:dim([A] | |code=:dim([A] | ||
− | :Matr►list(cumSum([A]) | + | :Matr►list(cumSum([A])<sup>T</sup>,Ans(1),L,,1,, |
:sum(L,,1,, | :sum(L,,1,, | ||
}} | }} | ||
− | The [[TI-BASIC:Cumsum|CumSum(]] command gets the cumulative sum of each column in the [[TI-BASIC:Matrices|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 | + | The [[TI-BASIC:Cumsum|CumSum(]] command gets the cumulative sum of each column in the [[TI-BASIC:Matrices|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 <sup>[[TI-BASIC:Transpose|T]]</sup> (transpose) of the resulting matrix switches columns and rows. |
− | Then, using the [[TI-BASIC: | + | Then, using the [[TI-BASIC:Matr_List|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 [[TI-BASIC:Cleanup|clean it up]] at the end of your program.[[Category:TI-BASIC]] | 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 [[TI-BASIC:Cleanup|clean it up]] at the end of your program.[[Category:TI-BASIC]] | ||
[[Category:TIBD]] | [[Category:TIBD]] |
Latest revision as of 23:22, 24 February 2016
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
zadaURL: United TI Download
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.