Variables are the meat of any programming language as they are used to store and work with data. With variables, the outcomes of programs can differ depending on the user's input or the purpose of the program. Variables in the TI calculators can store different types of data, whether it be numbers, lists of numbers, strings, mathematical functions, etc. However, each data type has its own type of variable that it can be stored in and the rules must be followed fairly strictly.
TI-BASIC is unusual among programming languages in that it does not support actual variables. Instead, all data are treated like files; there is no distinction between an ordinary number and an image, for example. TI refers to all files as "variables." Henceforth, "variable" will refer to a file usable by a program.
There are many types of variables, but in this chapter, only the most common ones will be dealt with. TheAdvanced Variables section will deal with the more complex variable types and uses. The following sections will deal with:
1,-0.5,3.14,i,3i+2){1 2 3 4 5})"HELLO, WORLD")Variables can be stored and recalled at the home screen, or within a program by simply using that variable's name. The method for recalling variables varies depending on the type of variable:
To recall the value ofX, pressALPHA[X], then pushENTER:
{{{1}}}or to recallStr1:
{{{1}}}or to recallL1:
{{{1}}}Numbers are stored into variables labelledA throughZ andθ and can be real or complex numbers (complex numbers can only be used if the calculator is ina+bi orre^θi modes).
Number variables store both the integer and decimal part of a number. Examples of number variables are0,2.1,5,7.212,3i, or3.1415926. Number variables are accurate up to eight significant digits and can be in the range of-9ᴇ99 to9ᴇ99 (). If an attempt is tried to evaluate or store a value outside of the range, the calculator returns an error.
The calculator can updateX,Y,R,θ, andT during graphing, so you may want to avoid using these variables to store non-graphing data.
To store a number to a number variable, the syntax is as follows:
value→variable
5.32→X
A→X
In this example, only the value ofA is stored toX (i.e., changes toA will not be reflected inX after the assignment).
10/2+36+89/A→X
In this example, ifA = 89,X = 42, not the actual equation. Only the result of an equation is stored (the equation is5+36+89/89 = 42, soX = 42).
Lists are essentially an array: they store an array of numbers. The individual numbers of a list are named elements. The maximum number of elements in a list is999.
{value1,value2,...,valueN}→listNameL1,L2,L3,L4,L5,L6L (2ND[LIST]OPS B) followed by characters denoting a name, maximum of 6 tokens, letters only999.To instantiate a list, the following code is used:
L1 if it exists, and the second line instantiatesL1 with a size ofn.It is important to first instantiate a list before attempting to access it so that the size is appropriate for usage. Thedim( (2ND [LIST]OPS 3) command stands fordimension, and in this case, we have setn as the dimension (or size) of the list.
To access a single element in a list, use the formatL1(N), whereN is the N-th element in the list. The index is 1-indexed, so to reference the first element inL1, useL1(1).
If you try to access an element that is out of the bounds of the size of the list (accessing thenth element where the size of the list is less thann orn is less than 1), you will receive an error. |
Lists can only store numbers.
{15,20,30}→L1
{1,2,3,4,5}→LMYLIST
L1→L2
{15,20,30}+5→L1
In this example,L1 would consist of{20 25 35} because each element was increased by5 then stored toL1.
Strings hold text.
string→strN
"BOB SMITH"→Str1
Str1→Str2
"MY NAME IS "+Str1+" AND YOU KNOW IT!"→Str2
It should be noted that variables can only contain their respective data type. For example, trying to store a number to a string object (0→Str1) will result in an error.
Try these examples to practice using the different data types.
Use variables to store numbers, then perform simple operations on them. Make variables A and B equal to 3 and 7, respectively. Then output,, and.
Solution |
|---|
Which outputs: {{{1}}} |
Create a simple list using these numbers:3,6,8. Now, usingDisp, output each value to the screen, then output the average of the values of the list by accessing them from the list.Remember, to type a list, press2ND then a number from 1-6.
Solution |
|---|
Which outputs: {{{1}}} |
SetStr1 to your first name and setStr2 to your last name. Then, using string concatenation, print your first and last names on two lines, with preceding textFIRST: andLAST:. For example, your output would appear as follows:
{{{1}}}Solution |
|---|
|
Previous:Hello, World!
Next:Output
Table of Contents:TI-Basic Z80 Programming