Showing posts with label IF THEN ELSE. Show all posts
Showing posts with label IF THEN ELSE. Show all posts

Monday, July 3, 2017

Programming Languages: TI-85 vs. TI-84 CE Plus

Programming Languages:  TI-85 vs. TI-84 CE Plus

I purchased a 1995 edition of the TI-85 at a Pasadena City College swap meet.  The TI-85 was my go-to and favorite calculator through high school (1991 – 1995). 

Today, I am going to compare common programming commands between two of my favorite Texas Instrument calculators, the TI-85 and the current TI-84 CE Plus.  The manuals for each calculator were consulted to answer questions.

Arguments in vector brackets [ ] means the argument is optional.

Command
TI-85 (1992 – 1997)
(probably also applies to the TI-86)
Software Version 10.0
TI-84 CE Plus (2016-)
(most of the this applies to TI-84 Plus 2004-present)
Software Version 5.2.2
Variable Names
Up to 8 characters, must begin with a number, no spaces.
All variables are global.
Single letters A through Z, n, θ
All variables are global.
Complex Number display, Rectangular
(X, Y)
X + Yi
Complex Number display, Polar
(R θ)
R e^θi
Graphing Modes
Function, Polar, Parametric, Differential Equation
Function, Polar, Parametric, Recurring Sequences
Number of Colors
0 (monochrome display)
15: blue, red, black, magenta, green, orange, brown, navy, light blue, yellow, white, light gray, medium gray, gray, dark gray (backlit display)
**CE and C versions only
Input
Input by itself displays the graph screen

Input [“prompt string”], varname
Input by itself displays the graph screen

Input  [“prompt string”], variable
Prompt:  asking for and storing multiple values
Prompt var1, var2, var3 ,…
Prompt var1, var2, var3, …
Disp
Disp by itself displays the home screen

Disp var/string, [var/string …]
Disp by itself displays the home screen

Disp var/string, [var/string…]
Pause
Pause [var/string]
Pause [var/string], [time in seconds]
Wait
N/A
Wait time in seconds up to 100
Display the graph screen
DispG
displays the graph screen
DispGraph
displays the graph screen
Display the function table
N/A
DispTable
Output
Outpt(line, col, var/string)
8 lines, 21 columns
Output(row, col, var/string)
10 rows, 26 columns
InpSt
InpSt stores entered text or equations as strings
N/A.  Use Input
If – Then – Else structure
If condition
Then
do if true
[Else
do if false]
End
If condition
Then
do if true
[Else
do if false]
End
For structure
For(var, begin, end, [step])
commands
End
For(var, begin, end, [step])
commands
End
While structure
While condition
do while condition is true
End
While condition
do while condition is true
End
Repeat – Until structure
Repeat condition
do while condition is false
End
Repeat condition
do while condition is false
End
Menu
Menu(nn, string, label…)
Where nn is from 1 to 15
Menu(“title”, “text”, label…)
Up to 9 options
Labels (Lbl/Goto)
Label names can have up to 8 characters.  All labels are local.
A-Z, 0 -99, θ.  All labels are local.
Increment (by 1) and Skip (if greater to value)
IS>(variable, value)
IS>(variable, value)
Decrement (by 1) and Skip (if less than value)
DS<(variable, value)
DS<(variable, value)
Stop program execution
Stop
Stop
Return from a subroutine
Return
Return
Execute a subroutine
Type the name of the program
Call program by pressing [prgm], choosing it from the Program submenu during editing
Clear the graph screen
ClDrw (clear all drawings)
ClrDraw (clear all drawings)
Display text on a graph screen
N/A
TextColor(color) sets the color.
Text([-1], row, col, string)
0-164 row pixel,
0-264 column pixel
-1 is for large text
Draw a temporary function
DrawF f(x)
DrawF f(x), [color]

Draw a temporary inverse function (f^-1(x) = y, x and y are swapped)
DrInv f(x)
DrawInv f(x), [color]
Shading
Shade (lower, upper, left, right)
Shade (lower, upper, [left, right, pattern, pattern resolution, color])
Draw a line
Line(x1, y1, x2, y2)
Line(x1, y1, x2, y2, [0/1, color, line style])
0/1: 0 to erase, 1 to draw
Draw a circle
Circle(x, y, radius)
Circle(x, y, radius, [color, line style])
Draw a Point
Only the TI-84 Plus CE has similar commands for pixels
PtOn(x,y)
PtOff(x,y)
PtChg(x,y)
Pt-On(x,y, [mark, color])
Pt-Off(x,y,[mark])
Pt-Change(x,y,[color])
Convert a value to a string
N/A
eval(expression) → Str#
No complex results
Convert a string to a value
N/A
expr(string)
Convert a string to a graph variable
St>Eq(string, graph variable)
String>Equ(string, graph variable)
Length of a string
lngth string
length(string)
(call from the catalog)
Extract part of a string
sub(string, begin point, length)
sub(string, begin point, length)
(call from the catalog)
Execute Linear Regression analysis (other regressions are similar)
LinR xlist, ylist
LinReg(ax+b) xlist, ylist, [freqlist, Y= variable]
Turn a stat plot on
N/A (stat plots are not available on the TI-85)
PlotsOn [1,2,3]
Turn a stat plot off
N/A (stat plots are not available on the TI-85)
PlotsOff [1,2,3]
Turn graph functions on
FnOn [1 – 99]
FnOn [1-9, 0]
Turn graph functions off
FnOff [1 – 99]
FnOff [1-9, 0]

Notes

As we can see, the programming language of the TI-85/86 family is similar to the TI-84 Plus family, translating the programs should not be difficult.  I believe that stat plots are available on the TI-86, but not the TI-85.

Keep in mind if you have complex numbers, that the complex mode on the TI-84 Plus (a+bi or re^(θi) has to be turned on.  Furthermore, logarithmic, power, exponential, and trigonometric functions for complex numbers return error on the TI-84 Plus (substitute expressions must be used).

(use radians mode)
With z = X + Yi = R*e^(θ*i), X = real(z), Y = imag(z), R = abs(z), θ = arg(z)

z^n = R^n * (cos(n*θ) + sin(n*θ)*i), n is a real number
ln (z) = ln R + θ*i
e^(z) = e^X * cos Y + e^X * sin Y * i
sin(z) = sin X * cosh Y + cos X * sinh Y * i
cos(z) = cos X * cosh Y – sin X * sinh Y * i
sin¯¹ (z) = asin(z) = -i * ln (zi ± √ (1 – z^2)
z1 ^ z2 = e^(z2 * ln z1)

Eddie


This blog is property of Edward Shore, 2017

Saturday, October 26, 2013

HP Prime Programming Tutorial #2: MSGBOX, IF-THEN-ELSE, PRINT, FOR


Welcome to another programming tutorial for the HP Prime. In this session, we will cover MSGBOX, IF-THEN-ELSE, PRINT, and the FOR loop.

MSGBOX

MSGBOX: MSGOX takes a string a makes a pop-up message box. Program execution stops until you press a key to acknowledge the message.
Access: Cmds, 6. I/O, 8. MSGBOX

The program COMLOCK: Imagine that you are in charge of setting the combinations for the good, old-school combination locks. This program gives three digit combinations through the use of MSGBOX.

EXPORT COMLOCK()
BEGIN
LOCAL L0;
L0:=RANDINT(3,0,39);**
MSGBOX("SECRET: "+L0(1)+","+L0(2)+","+L0(3));
END;  

** Thanks to Thomas Lake for pointing out my typo.  Apologies for any inconvenience - Eddie (3/21/2014)

Other commands that are featured:

RANDINT(n, a, b) generates a list of n integers between a and b. You can leave n out if you desire a single random integer. Picks may be repeated.

The HP Prime's default list variables are designated L0 through L9.



Here is a sample output for COMLOCK:



IF-THEN-ELSE

IF-THEN-ELSE: Program structure:
IF condition THEN
do if the condition is true;
ELSE
do if the condition is false;
END;


Access: Tmplt, 2. Branch, 2. IF THEN ELSE


Tip: You can leave out the ELSE part if you only want to test to see if a condition is true. Access the simple IF-THEN structure by pressing Tmplt, 2. Branch, 1. IF THEN.

Access <, ≤, ==, etc. by pressing Shift, 6. Note that the double equals is needed to check equality.





PRINT

PRINT: The PRINT command prints a sting, result, or a combination of both onto the Prime's Terminal screen. If PRINT is used, the program will end on the terminal (text output) screen. Press a button to exit.

You can access the terminal screen at any time by pressing the ON button, holding it, and then pressing the Divide ( ÷ ) button.

Access: Cmds, 6. I/O, 9. PRINT

Tip: To clear the terminal screen, type PRINT(). This is a good way to clear the terminal screen and I usually use this at the beginning of any program if PRINT is going to be used later on.


The program QROOTS (yet one more quadratic solver, sorry for not being original guys and gals), demonstrates the use of IF-THEN-ELSE and PRINT.

Here I set the setting variable HComplex to 1, which allows for complex number results.

EXPORT QROOTS(A,B,C)
BEGIN
LOCAL D;
PRINT();
HComplex:=1;
D:=B^2-4*A*C;
IF D≥0 THEN
PRINT("Roots are real.");
ELSE
PRINT("Roots are complex.");
END;
PRINT((-B+√D)/(2*A));
PRINT((-B-√D)/(2*A));
END;


Examples:

QROOTS(1,5,8) returns:

Roots are complex.
-2.5+1.32287565553*i
-2.5-1.32287565553*i

QROOTS(2,-4,-8) returns:

Roots are real.
3.2360679775
-1.2360679775


FOR

This section will explore the basic FOR structure:

FOR variable FROM start TO end DO
commands;
END;


All the commands in the loop will be executed a set number of times. Each time a loop finishes, the variable increases by one. The loop terminates when variable=end.

Access: Tmplt, 3. LOOP, 1. FOR


The program SUMDIV takes any integer and adds up the sum of its divisors. For example, the divisors of 12 are 1, 12, 2, 3, 4, and 6. The sum is 28.


Featured Commands in SUMDIV:

idivis: idivis(integer) returns a sequence of all of the divisors if integer. Access: Toolbox, CAS, 5. Integer, 1. Divisors

Any CAS command used in programming will be preceded by "CAS." Not all CAS commands can be used in HP Prime programming at this time.

DIM: returns the dimensions of a sequence, string, or matrix. DIM must be used instead of SIZE to prevent a Bad Argument error.

For sequences or vectors, DIM returns the length in a list {length}.
For strings, DIM returns length as a number.
For matrices, DIM returns the list {number of rows, number of columns}.

Access: Cmds, 1. Strings, 9. DIM


The program:

EXPORT SUMDIV(N)
BEGIN
LOCAL S:=0,K,mdiv,ldiv;
mdiv:=CAS.idivis(N);
ldiv:=DIM(mdiv);
FOR K FROM 1 TO ldiv(1) DO
S:=S+mdiv(K);
END;
RETURN S;
END;  
** Thanks to Thomas Lake for pointing out that the variable "mat", which I had in this program was unnecessary.  - Eddie 3/21/2013
 

Examples:
SUMDIV(12) returns 28.
SUMDIV(24) returns 60.
SUMDIV(85) returns 108.



This concludes this part of the HP Prime Programming Tutorial.

HAPPY HALLOWEEN!

Eddie


This blog is property of Edward Shore. 2013



First Look: HP 16C Collector's Edition

 First Look: HP 16C Collector's Edition I just got the HP 16C Collector's Edition.   This is the famous HP 16C that specializes in c...