In this series of tutorials I will teach you how to program in a TI 82 calculator from the very basics. I use a TI 82 calculator and therefor I also use it for my examples but many different Texas Instruments calculator has nearly the same syntax so you don't have to use it with a TI 82.
All my knowledge I have got by testing on boring math lessons so I've tried a lot and know what to do and what you shouldn't do.![]()
Parts in this series:
- Part 1 - The very basics
- Part 2 - If statements and loops
- Part 3 - Receiving Inputs
- Part 4 - Matrixes and Lists
- Part 5 - Creating a Game
Anyway, let's start with Part 4 - Matrixes and Lists.
Matrixes and Lists are two ways to store a lot of data, the Matrixes uses 2 dimensions while Lists only use one.
Matrixes:
Matrixes hold numbers in a two dimensional storage, you get and set the value of one of the values by referring to its index(width and height).
There are a total of 10 Matrixes you can use, named from [A] to [J], to access them and also a list of the functions, press the MATRX button.
To create a new one we do this:
We then creates a Matrix with 5 in width and 5 in height and store is as Matrix [A], this means matrix [A] has room for 25(5*5) values.Code:{5,5}->dim([A])
Now if we want a value from the Matrix, for example, at position 3,2, we just referrer to that position like this:
We can do the same when we set the value:Code:[A](3,2)
Code:7->[A](3,2)
Just to show another example on how to do this I give you a little more complex example:
We using a nested for loop to create a multiplication table(X position multiplied with Y position is equals to the stored value at that position). Then the user can select a X value and a Y value and the value at that index in [A] is displayed. Observe that if X or Y is not between 1 and 5 an error will occur since there's no value at that index, this can be avoided by just make the game check the X and Y variables with an If statement before.Code:{5,5}->dim([A]) For(X,1,5,1) For(Y,1,5,1) X*Y->[A](X,Y) End End Prompt (X) Prompt (Y) Disp [A](X,Y)
When working with Matrixes you can use function which randomly fill the matrix, function to add rows and swap them and so on, but we won't go through that.
Lists:
To access the list of your Lists and all functions for lists press the "2nd" button and then the "STAT" button.
Lists holds a lot of data in a long line of values, list are only using one dimensional. A good thing with lists is that you can create as many of them as you like, you just use a custom name for them.
To declare a new one, it's just to use the length we want and stores it like this:
(the L in the name is actually a smaller L just indicating it's a list)Code:5->dim(LTEST)
This code creates a new List called TEST with a total of 5 elements. If the list already exists the length is just changed.
To access the value we just referrer to the position we want to get the value from, like this example:
That displays the value at position 3 in the list, in the same way we can also set the values:Code:Disp LTEST(3)
Now we add 25 as the value at position 3 in the list.Code:25->LTEST(3)
As I did with the Matrixes I can give you a little more complex example here too:
Code:5->dim(LTEST) 25->LTEST(1) 16->LTEST(2) 8->LTEST(3) 11->LTEST(4) 19->LTEST(5) 0->C For(I,1,5,1) If LTEST(I)>14 C+1->C End Disp "PUPILS PASSED:" Disp C
This code above creates a list with 5 elements and gives them different values. Then with a for loop the program check if each element's value is greater then 14, if this is the case, the variable C is increase by 1. Then the results are displayed.
When using lists we can use functions to sort the elements, get random lists and so on. But we won't learn that now.
Now we're done here, let's finish this off in Part 5.![]()
Last edited by Vswe; 08-28-2009 at 04:21 PM.
Getting better and better. +rep
This is where I think the HP calculators get better. They can disassemble and reassemble matrices on the fly. +rep
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks