Texas Instruments TI-92 Calculator User Manual


 
286 Chapter 17: Programming
17PROGRM.DOC TI-89/TI-92 Plus: Programming (English) Susan Gullord Revised: 02/23/01 1:14 PM Printed: 02/23/01 2:18 PM Page 286 of 40
When you create a new function in the Program Editor, the
TI
-
89 / TI
-
92 Plus
displays a blank “template”.
If the function requires input, one or more values must be passed to
the function. (A user-defined function can store to local variables
only, and it cannot use instructions that prompt the user for input.)
There are two ways to return a value from a function:
¦
As the last line in the function
(before
EndFunc
), calculate the
value to be returned.
:cube(x)
:Func
:x^3
:EndFunc
¦
Use
Return
. This is useful for
exiting a function and returning
a value at some point other than
the end of the function.
:cube(x)
:Func
:If x<0
: Return 0
:x^3
:EndFunc
The argument
x
is automatically treated as a local variable. However,
if the example needed another variable, the function would need to
declare it as local by using the
Local
command (pages 288 and 290).
There is an implied
Return
at the end of the function. If the last line is
not an expression, an error occurs.
The following function returns the
xth
root of a value
y
(
x
y
). Two
values must be passed to the function:
x
and
y
.
Function as called from the Home Screen
Function as defined in
the Program Editor
4
ù
xroot(3,125) 20
:xroot(x,y)
:Func
:y^(1/x)
:EndFunc
Entering a Function
Note: Use the cursor pad to
scroll through the function
for entering or editing
commands.
How to Return a
Value from a
Function
Note: This example
calculates the cube if x
0;
otherwise, it returns a 0.
Example of a
Function
Note: Because x and y in
the function are local, they
are not affected by any
existing x or y variable.
Function name, which you
specify when you create a
new function.
Enter your commands
between
Func
and
EndFunc
.
All function lines begin
with a colon.
3!x:125!y
5
Be sure to edit this line to
include any necessary
arguments. Remember to
use argument names in
the definition that will
never be used when
calling the function.