Difference between revisions of "TI-BASIC:Matrices"
(Automated @@ correction) |
(Automated internal link correction) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
Matrices are two-dimensional lists (row by column). They are used for holding lots of information. Matrices are often used for storing a [[TI-BASIC:Maps|map]] of the screen, which is necessary for collision detection in [[TI-BASIC:Movement|Movement]]. | Matrices are two-dimensional lists (row by column). They are used for holding lots of information. Matrices are often used for storing a [[TI-BASIC:Maps|map]] of the screen, which is necessary for collision detection in [[TI-BASIC:Movement|Movement]]. | ||
− | There are only ten built-in matrices (from [A] to [J]). A matrix may have up to 99 rows and 99 columns, however the memory on a TI-83 calculator limits this: a 99x99 matrix would hold 9801 elements, and take up 88220 bytes! A matrix is like a grid. To access the matrix variables you need to press [MATRX] on a TI-83, or [2nd] <nowiki>[</nowiki>''x'' | + | There are only ten built-in matrices (from [A] to [J]). A matrix may have up to 99 rows and 99 columns, however the memory on a TI-83 calculator limits this: a 99x99 matrix would hold 9801 elements, and take up 88220 bytes! A matrix is like a grid. To access the matrix variables you need to press [MATRX] on a TI-83, or [2nd] <nowiki>[</nowiki>''x''<sup>-1</sup>] on a TI-83+ or higher. You can then scroll down to whatever matrix you want to use or press the corresponding number. Entering [, A, and ] for the matrix [A] will '''not''' work. |
The square brackets, [ and ], are used when manually entering a matrix variable. The syntax is fairly complicated, and goes as follows: | The square brackets, [ and ], are used when manually entering a matrix variable. The syntax is fairly complicated, and goes as follows: | ||
Line 21: | Line 21: | ||
* [[TI-BASIC:Add|Plus]](+) and [[TI-BASIC:Subtract|minus]](-) add or subtract the matching elements of two matrices with the same size (no surprise there). The [[TI-BASIC:Negative|negating]] (-) will negate each element of the matrix. | * [[TI-BASIC:Add|Plus]](+) and [[TI-BASIC:Subtract|minus]](-) add or subtract the matching elements of two matrices with the same size (no surprise there). The [[TI-BASIC:Negative|negating]] (-) will negate each element of the matrix. | ||
* [[TI-BASIC:Multiply|Multiplication]] (*) for matrices exists, but it does not work like adding and subtracting. For details, see [*http://mathworld.wolfram.com/MatrixMultiplication.html Matrix Multiplication] at MathWorld. | * [[TI-BASIC:Multiply|Multiplication]] (*) for matrices exists, but it does not work like adding and subtracting. For details, see [*http://mathworld.wolfram.com/MatrixMultiplication.html Matrix Multiplication] at MathWorld. | ||
− | * The [[TI-BASIC:Inverse|Inverse]] ( | + | * The [[TI-BASIC:Inverse|Inverse]] (<sup>-1</sup>) operator finds the inverse matrix, the NxN matrix such that [A]<sup>-1</sup>[A]=[A][A]<sup>-1</sup>=identity(N). This function only works for square matrices. |
* The [[TI-BASIC:Power|^]] operator raises a square matrix to a power, multiplying it by itself 0 to 255 times. The [[TI-BASIC:2|²]] and [[TI-BASIC:3|³]] commands are valid substitutes for ^2 and ^3. | * The [[TI-BASIC:Power|^]] operator raises a square matrix to a power, multiplying it by itself 0 to 255 times. The [[TI-BASIC:2|²]] and [[TI-BASIC:3|³]] commands are valid substitutes for ^2 and ^3. | ||
* The [[TI-BASIC:Equal|=]] operator tests if two matrices are exactly identical, and returns 1 if they are and 0 otherwise; [[TI-BASIC:Notequal|≠]] works similarly. | * The [[TI-BASIC:Equal|=]] operator tests if two matrices are exactly identical, and returns 1 if they are and 0 otherwise; [[TI-BASIC:Notequal|≠]] works similarly. | ||
* Some commands also work on matrices, by being applied to every element. They are: | * Some commands also work on matrices, by being applied to every element. They are: | ||
** [[TI-BASIC:Abs|Abs(]] and [[TI-BASIC:Angle|Angle(]] (but no other complex number commands) | ** [[TI-BASIC:Abs|Abs(]] and [[TI-BASIC:Angle|Angle(]] (but no other complex number commands) | ||
− | ** [[TI-BASIC: | + | ** [[TI-BASIC:Frac|►Frac]] and [[TI-BASIC:Dec|►Dec]] (but no other formatting commands) |
** [[TI-BASIC:Fpart|FPart(]], [[TI-BASIC:Ipart|IPart(]], [[TI-BASIC:Int|Int(]], and [[TI-BASIC:Round|Round(]] | ** [[TI-BASIC:Fpart|FPart(]], [[TI-BASIC:Ipart|IPart(]], [[TI-BASIC:Int|Int(]], and [[TI-BASIC:Round|Round(]] | ||
Line 42: | Line 42: | ||
<div style="float:left; width: 25%; padding: 0 2%"> | <div style="float:left; width: 25%; padding: 0 2%"> | ||
* [[TI-BASIC:Randm|RandM(]] | * [[TI-BASIC:Randm|RandM(]] | ||
− | * [[TI-BASIC: | + | * [[TI-BASIC:Matr_List|Matr►list(]] |
− | * [[TI-BASIC: | + | * [[TI-BASIC:List_Matr|List►matr(]] |
* [[TI-BASIC:Ref|Ref(]] | * [[TI-BASIC:Ref|Ref(]] | ||
* [[TI-BASIC:Rref|Rref(]] | * [[TI-BASIC:Rref|Rref(]] | ||
Line 53: | Line 53: | ||
* [[TI-BASIC:Timesrow|*row(]] | * [[TI-BASIC:Timesrow|*row(]] | ||
* [[TI-BASIC:Timesrowplus|*row+(]] | * [[TI-BASIC:Timesrowplus|*row+(]] | ||
− | * | + | * <sup>T</sup> ([[TI-BASIC:Transpose|Transpose]]) |
</div> | </div> | ||
Latest revision as of 23:53, 24 February 2016
Matrices are two-dimensional lists (row by column). They are used for holding lots of information. Matrices are often used for storing a map of the screen, which is necessary for collision detection in Movement.
There are only ten built-in matrices (from [A] to [J]). A matrix may have up to 99 rows and 99 columns, however the memory on a TI-83 calculator limits this: a 99x99 matrix would hold 9801 elements, and take up 88220 bytes! A matrix is like a grid. To access the matrix variables you need to press [MATRX] on a TI-83, or [2nd] [x-1] on a TI-83+ or higher. You can then scroll down to whatever matrix you want to use or press the corresponding number. Entering [, A, and ] for the matrix [A] will not work.
The square brackets, [ and ], are used when manually entering a matrix variable. The syntax is fairly complicated, and goes as follows:
- The matrix must start off with an opening bracket - [.
- After that comes the data in the matrix, row by row (left to right, and top to bottom).
- Each row begins with another opening bracket - [.
- Then come the elements in the row. Numbers or expressions, they must be separated by commas.
- A row ends with a closing bracket - ]. There is no comma between two rows.
- The matrix ends with another closing bracket - ].
Thus, a matrix will start with two opening brackets, ,_And_End_With_Two_Closing_Brackets,. If all you're doing is storing the matrix, the last two brackets can be omitted.
Fortunately for you, you don't have to memorize this syntax -- in fact, it's probably best if you don't, since there's good odds of making a mistake even if you know it well. The easiest way to store to a matrix variable in a program is first, to create the matrix you want in the matrix editor, and second, to paste it into the program by recalling the matrix's value.
Commands
Some basic arithmetic commands can be used by matrices as well as real numbers. However, they don't all do what you would expect (unless of course you've taken an advanced algebra class):
- Plus(+) and minus(-) add or subtract the matching elements of two matrices with the same size (no surprise there). The negating (-) will negate each element of the matrix.
- Multiplication (*) for matrices exists, but it does not work like adding and subtracting. For details, see [*http://mathworld.wolfram.com/MatrixMultiplication.html Matrix Multiplication] at MathWorld.
- The Inverse (-1) operator finds the inverse matrix, the NxN matrix such that [A]-1[A]=[A][A]-1=identity(N). This function only works for square matrices.
- The ^ operator raises a square matrix to a power, multiplying it by itself 0 to 255 times. The ² and ³ commands are valid substitutes for ^2 and ^3.
- The = operator tests if two matrices are exactly identical, and returns 1 if they are and 0 otherwise; ≠ works similarly.
- Some commands also work on matrices, by being applied to every element. They are:
There are also, of course, special commands for dealing with matrices. They are:
These can be found in the MATH submenu of the matrix menu.
Optimizations
Even if you need to store a fixed matrix in a program, doing it in the standard fashion is usually inefficient memory-wise: consider that if each element is one digit, then over half the memory used is spent on commas and brackets.
You may want to use a modified version of a routine on the compressions techniques page.
If most of your matrix's elements are 0, consider deleting the matrix (so that any old data in it doesn't interfere), creating it using the Dim( command with all elements 0, then storing to the elements that are not. For example:
:DelVar [A]{5,5→dim([A] :1→[A](1,2 :2→[A](3,4 :3→[A](5,5