[7.15] Avoid For; Avoid For ... Endfor Loops - Texas Instruments TI-89 Tip List

Graphing calculator
Hide thumbs Also See for TI-89:
Table of Contents

Advertisement

pid()→tmp
if mid(tmp,4,3)="0-0":return 1.0
if mid(tmp,4,3)="0-1":return 1.01
if mid(tmp,4,3)="1-3":return 1.05
return 0
endfunc
Frank also offers these comments on his code:
"In most cases none of this will be necessary. In the rare case that it is, it will probably be more useful
to incorporate fragments into a single function or program making the overall code much smaller.
I claim no rights to any of this code, it is all public domain.
There doesn't appear to be any way to determine hardware version programatically."
(Credit to Frank Westlake and Lars Fredericksen)

[7.15] Avoid For ... EndFor loops

Loops are very slow on the 89/92+. The 89/92+ provide some functions which can be used to
accomplish some operations that are traditionally done with loops:
! use PolyEval() to evaluate polynomials
! use seq() to generate a list of function values
! use sum() to add the elements of a list
! use sigma (Σ) to sum the values of an expression
! use upper-case pi (‹) to find the product of expression terms
! the common arithmetic operators (+, -, *, /, etc) operate on lists & matrices
! the 'dot operators' (.-, .*, ./, .^) operate on matrices and expressions
! the submat() function extracts part of a matrix
[7.16] Use when() instead of if...then...else...endif
The 92+ manual describes using when() only to create discontinuous graphs, however, it is much more
useful than that. It can be used in place of the if...endif construction, and is more compact.
when() functions can also be nested to create an if...then...else..endif structure. Suppose you have four
functions f1(x), f2(x), f3(x) and f4(x). You want to evaluate the functions on intervals like this:
f1(x) when x < 1
f2(x) when x>= 1 and x < 2
f3(x) when x>= 2 and x < 3
f4(x) when x >= 3
The If...EndIf version looks like this:
if x < 1 then
f1(x)
elseif x≥1 and x<2 then
f2(x)
7 - 16

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Ti-92+

Table of Contents