Difference between revisions of "TI-BASIC:Sum Of Matrix"

From Learn @ Cemetech
Jump to navigationJump to search
(Initial automated import)
 
(Automated internal link correction)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
{{Template:TI-BASIC:Routine
 
{{Template:TI-BASIC:Routine
|picture=@@
+
|picture=
 
|summary=Returns the sum of the elements of a matrix.
 
|summary=Returns the sum of the elements of a matrix.
 
|input=''[A]'' - the matrix whose elements you want to sum
 
|input=''[A]'' - the matrix whose elements you want to sum
Line 7: Line 7:
 
|compatibility=TI-83/84/+/SE
 
|compatibility=TI-83/84/+/SE
 
|author=zada
 
|author=zada
|authors=@@
+
|authors=
 
|url=http://www.unitedti.org/index.php?showtopic=7475&view=findpost&p=117106 United TI
 
|url=http://www.unitedti.org/index.php?showtopic=7475&view=findpost&p=117106 United TI
 
|download=[file sumofmatrix.zip]
 
|download=[file sumofmatrix.zip]
Line 14: Line 14:
 
{{Template:TI-BASIC:Prgm-code
 
{{Template:TI-BASIC:Prgm-code
 
|code=:dim([A]
 
|code=:dim([A]
:Matr►list(cumSum([A])^^T^^,Ans(1),L,,1,,
+
: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 ^^[[TI-BASIC:Transpose|T]]^^ (transpose) of the resulting matrix switches columns and rows.
+
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: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.
+
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

file sumofmatrix.zip

Template:TI-BASIC:Prgm-code

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.