TI Nspire Programming
TI Nspire Programming
com
Why Programming?
1. Programming is a passion of mine. Logic is fun! 2. The amount of work to do always increases, while the amount of people to do it almost never does. I feel that truly effective people find ways to automate repetitive tasks in their every day life. 3. For some students, Programming is a tangible way to teach abstract concepts of logic, causality, critical thinking, and even empathy!
Progra what?
An Algorithm is a list of instructions to accomplish a goal. Think of an Algorithm as a Recipe
Ingredients become Variable Declarations Steps become Code Yield becomes Return
A Scripting Language is translated from the language to machine language at runtime (Interpreting) using a piece of software called an Interpreter.
Changes can be made and tested on the fly. Easier to debug.
Prgm vs Func
In the world of the TI-Nspire
A Program (Prgm) is an expression of an algorithm.
Variables can be local or global. Does not return a response just output.
Some Terminology
Debugging is the process of stepping through code, finding, and fixing issues. A Block is container for code. An example, the Prgm and EndPrgm statements form a Prgm Block. Everything between those statements are treated as a program. A Conditional statement offers boolean criteria (true or false) and effects based on the response, essentially a choice for the program.
A Loop allow you to repeat steps. A loop allow you to repeat steps. A loop allow you to repeat steps
Error Terminology
A Syntax Error generally means that you used a function or command incorrectly. For instance:
Solve(2x=0) would produce a syntax error, since the Solve() command requires an expression, a comma, and then a variable.
A Domain Error generally indicates that a calculation is out of the range of the calculators capabilities.
Logic Errors
The beauty of code: It does exactly what you tell it to do. The frustration of code: It does exactly what you tell it to do.
Logic Errors are errors in which the commands and functions are used in their proper syntax, but the code doesnt produce the expected outcome.
This is usually because of human errors in planning. These types of issues are common. At some point, every good programmer ends up crawling lines of code looking for an errant line. Its a rewarding find.
Once youre here, start filling in the name of your program, choosing whether its a program or a function, and setting its library access.
Library Access?
LibPriv means that the function or program will be available from any document, but will not display in the catalog. LibPub means that the function or program will be available from any document, and will display in the catalog. None or leaving out LibPriv/LibPub means that the function or program will only be accessible from the current document. (This is the default) You can write your functions or programs in one document using LibPriv or LibPub, and then access those programs or functions from any document!
Define hello()=
Prgm
Disp Hello World! EndPrgm
A Hello World program is a good way to learn the most basic structure of a programming language.
With this program, well spice things up by adding a loop and input. Since we want to return a value (making the result useful outside the program itself), well do this one as a function.
For the loop, I chose a For..EndFor loop since we know how many times we want to run through.
The idea is, we run the function specifying how many elements we want, and the function outputs a list of that many random integers between 0-9.
EndFunc
Define evenodd(a)= Prgm For i,1,dim(a),1 If mod(a[i],2)=0 Then Disp a[i], is even. Else Disp a[i], is odd. EndIf EndFor EndPrgm
For a conditional, we use If..Then..ElseEndif. The device will evalute the stuff between If and Then, and if it is true, will execute the statements after Then. If the statement is not true, we go to Else, or exit the conditional nothing else is specified.
Next Steps
Functions are infinitely useful! You can use your functions to manipulate data in Lists and Spreadsheets, on graphs (using the Calculate tool), and in Calculator. Programs are growing more useful thanks to the TINspire 2.0 addition of the Request and RequestStr commands for taking input. Always remember to Check Syntax and Save before testing your creations!
Questions?