Showing posts with label TI-74 Basicalc. Show all posts
Showing posts with label TI-74 Basicalc. Show all posts

Sunday, April 30, 2023

TI-74 and Python (Casio fx-9750GIII): A Treasure of Programs

TI-74 and Python (Casio fx-9750GIII):  A Treasure of Programs



Today's programs illustrates an approach from both the BASIC and Python programming languages. 



Skiing Stars



This program paves a ski path by randomly plotting a path.  A slight difference:  the TI-74 version goes indefinitely until the user presses a key and uses one line.  The Python version goes 50 steps and the result must be scrolled up after the program completes.  I optimized the program to fit each screen.


TI-74 BASICALC Program


100 REM "Skiing Stars"

102 RANDOMIZE RND

104 P=14

106 PRINT "Press any key to stop.": PAUSE .25

120 CALL KEY(K,S)

122 IF S<>0 THEN 140

124 R=RND

126 IF R<.4 AND P>0 THEN LET P=P-1

128 IF R>.4 AND P<26 THEN LET P=P+1

130 DISPLAY ERASE ALL AT(P),"*****": PAUSE .15

132 GOTO 120

140 PRINT RPT$("*",31): PAUSE .25

142 STOP


Python (Casio fx-9750GIII):  skistar.py


# skiing stars

from random import *

rnd=int(10000000*random())

seed(rnd)

p=8

for i in range(50):

  r=random()

  if r<.4 and p>0:

    p-=1

  if r>.6 and p<14:

    p+=1

  print(" "*p+"*****")

print("scroll up")

    


Phase Speed of a Wave


Equation:

c = √( g  * λ / (2 * π) * tanh(2 * π * d / λ))


c = phase speed

λ = wavelength 

d = water depth

g = Earth's gravity = 9.80665 m/s = 32.174049 ft/s


Source:


"Wind Wave"  Wikipedia.  Last Edited January 28, 2023.  Accessed February 14, 2023.  https://en.wikipedia.org/wiki/Wind_wave#:~:text=In%20fluid%20dynamics%2C%20a%20wind,is%20known%20as%20the%20fetch.


TI-74 BASICALC Program:  


400 REM Phase Speed

402 PRINT "U.S. units used": PAUSE .25

404 T=2*PI: G=32.174049

406 INPUT "Depth (ft)? "; D

408 INPUT "Wavelength (ft)? "; L

410 C=SQR(G*L/T*TANH(T*D/L))

412 PRINT "Phase Speed (ft/s)=": PAUSE .25

414 PRINT C: PAUSE

416 STOP


Python (Casio fx-9750GIII): phspeed.py  


# phase speed

from math import *

print("U.S  units used")

t=2*pi

g=32.174049

print("Depth (ft)?")

d=float(input())

print("Wavelength?")

l=float(input())

c=sqrt(g*l/t*tanh(t*d/l))

print("Phase speed (ft/s)=")

print(c)


Example:


Depth:  2.26 ft

Wavelength:  18.9 ft


Result:  

Phase Speed:  7.845145563 ft/s



Horsepower Generated by a Wave


p = 0.0329 * h^2 * √( l * (1 - 4.935 * (h^2/l^2))


h = wave height (ft)

l = length of a wave (ft)

p = horsepower


Source: 


Rosenstein, Morton.  Strategies for Scientific Calculating Casio.  January 1982.


TI-74 BASICALC Program:


500 REM horsepower of a wave

502 PRINT "U.S. units used": PAUSE .25

504 INPUT "Wave height (ft)? ";H

506 INPUT "Length of wave (ft)? "; L

508 P=.0329*H^2*SQR(L*(1-4.935*(H^2/L^2)))

510 PRINT "Horsepower = ": PAUSE .25

512 PRINT P: PAUSE

514 STOP


Python (Casio fx-9750GIII):  hpwave.py


# horsepower of a wave

from math import *

print("U.S. units used")

print("Wave height (ft)?")

h=float(input())

print("Length of a wave?")

l=float(input())

p=.0329*h**2*sqrt(l*(1-4.935*(h**2/l**2)))

print("horsepower = ")

print(p)


Example:


Wave height:  1.26 ft

Length of wave: 24.04 ft


Result:

Horsepower = .2543549811 hp



Until next time,


Eddie



All original content copyright, © 2011-2023.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


Saturday, April 29, 2023

TI-74 and Python (Casio fx-9750GIII): Probability

TI-74 and Python (Casio fx-9750GIII):  Probability



Today's program illustrates an approach from both the BASIC and Python programming languages. 


The program offers the user to calculate common probability problems:



1)  n!:  factorial of an integer

2)  nCr:  combinations without replacement

3)  nPr:  permutations

4)  nHr:  combinations with replacement

5) bday:  probability that n people do not share a category in common from a size of categories (i.e. birthday problem:  How many people in a room don't share a birthday?)



TI-74 BASICALC Program


200 REM probability

202 INPUT "1)n! 2)nCr 3)nPr 4)nHr 5)bday "; I

204 IF I<5 THEN INPUT "n? "; N

206 IF I>1 AND I<5 THEN INPUT "r? "; R

208 ON I GOTO 220,240,260,280,300


220 X=N

222 GOSUB 320

224 PRINT "n! = "; F: PAUSE

226 GOTO 340


240 Z=1: FOR K=(N-R+1) TO N: Z=Z*K: NEXT K

242 X=R: GOSUB 320

244 Z=Z/F

246 PRINT "nCr = "; Z: PAUSE

248 GOTO 340


260 Z=1: FOR K=(N-R+1) TO N: Z=Z*K: NEXT K

262 PRINT "nPr = "; Z: PAUSE

264 GOTO 340


280 Z=1: FOR K=N TO (N+R-1): Z=Z*K: NEXT K

282 X=R: GOSUB 320: Z=Z/F

284 PRINT "nHr = "; Z: PAUSE

286 GOTO 340


300 INPUT "# categories? "; R

302 INPUT "Sample size? "; N

304 Z=1: FOR K=1 TO (N-1): Z=Z*(1-K/R): NEXT K

306 PRINT "P(all unique) = "; Z: PAUSE

308 GOTO 340


320 F=1

322 FOR K=1 TO X: F=F*K: NEXT K

324 RETURN


340 INPUT "Again? 0:No, 1:Yes "; A

342 IF A=1 THEN 202

344 IF A=0 THEN STOP

346 GOTO 340



Python Program:  prob.py 


Program completed with the Casio fx-9750GIII.


# probability

from math import *


def fact(x):

  f=1

  for k in range(1,x+1):

    f*=k    

  return f



fc=1


while fc!=0:

  print("1)n! 2)nCr")

  print("3)nPr 4)nHr")

  print("5)bday")

  ch=int(input())

  if ch<5:

    n=int(input("n? "))

  if ch>1 and ch<5:

    r=int(input("r? "))

  if ch==1:

    f=fact(n)

    print("n! = "+str(f))

  if ch==2:

    f=fact(n)/(fact(n-r)*fact(r))

    print("nCr = "+str(f))

  if ch==3:

    f=fact(n)/fact(n-r)

    print("nPr = "+str(f))

  if ch==4:

    f=fact(n+r-1)/(fact(r)*fact(n-1))

    print("nHr = "+str(f))

  if ch==5:

    r=int(input("# categories? "))

    n=int(input("Sample size? "))

    f=1

    for k in range(n):

      f*=1-k/r

    print("p(all unique)=")

    print(str(f))

  print("Again? 0)no 1)yes")

  fc=int(input())    


Examples


1) n!  

13! = 6227020800


2) nCr

n = 13, r = 6; result:  1716


3) nPr

n = 13, r = 6; result:  1235520


4) nHr

n = 13, r = 6; result:  18564


5) bday

# categories: 13

Sample size: 6

Result:  P(all unique) = .2559703523



Wishing you an excellent day.   More BASIC and Python programming coming your way tomorrow!


Eddie


All original content copyright, © 2011-2023.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


Thursday, September 8, 2016

TI-74 Programming: Factorial, List of Random Integers, 2 x 2 Matrix Determinant and Inverse, Simple Pendulum, Secret Codes

TI-74 Programming: Factorial, List of Random Integers, 2 x 2 Matrix Determinant and Inverse, Simple Pendulum, Secret Codes


Note:  The TI-74 has one programming space (lines 0 to 32768), which the entire space can be saved if the TI-74 connected to an appropriate peripheral (cassette or computer).  Cassettes?  The TI-74 is a 1980s basic computer after all. 

TI-74 Program Factorial

The TI-74 does not have a factorial function its command set.  Here is one way to tackle it:

1300 ! Factorial
1310 INPUT “N=”; N
1320 IF N=0 THEN PRINT 0: PAUSE: STOP
1325 F=1
1330 IF I=1 TO N-1
1340 F=F*I
1350 NEXT I
1360 PRINT “N!=”; F: PAUSE
1370 END

TI-74 List of Random Integers

Integers will appear for 2 seconds followed by a “Next…” indicator. 

1000 ! List of random integers
1005 RANDOMIZE
1010 INPUT “Length?”; K
1020 INPUT “High Number:”; N
1025 FOR I=1 TO K
1035 PRINT INT(N*RND+1): PAUSE 2
1040 PRINT “Next…”: PAUSE 0.5
1045 NEXT I
1050 PRINT “Done”: PAUSE: END

TI-74 2 x 2 Matrices: Determinant and Inverse

Matrix:  [[A, B],[C, D]]
Inverse:  [[F, G],[H, I]]
Determinant: E = A*D – B*C.  If E=0, the matrix is singular.

1100 ! 2 x 2 Matrices; det/inv
1105 INPUT “A=”; A, “B=”; B
1110 INPUT “C=”; C, “D=”; D
1115 E=A*D-B*C
1120 PRINT “det=”; E: PAUSE 2
1125 IF E=0 THEN STOP
1130 PRINT “inv=”: PAUSE 2
1135 F = D/E: G = -B/E: H=-C/E: I=A/E
1140 PRINT “F=”; F: PAUSE 2
1145 PRINT “G=”; G: PAUSE 2
1150 PRINT “H=”; H: PAUSE 2
1155 PRINT “I=”; I: PAUSE 2
1160 END

Example:
Matrix:  [[1, 5],[-2, 7]]
A=1,  B=5, C=-2, D=7

RUN 1100:
det = 17
inv =
F = .4117647059
G = -.2941176471
H = .1176470588
I = .0588235294

TI-74 Simple Pendulum:  Angular Velocity and Period

This routine calculates the angular velocity and period for a simple pendulum.  SI units are used, meaning that g = 9.80665 m/s^2.  Note the SQR command is square root.

1200 ! Simple Pendulum, SI unites
1205 G=9.80665
1210 INPUT “Length (m):”; L
1215 W=SQR(G/L): T=2*PI*SQR(L/G)
1220 PRINT “Angular Vel.:”; W; “m/s”:  PAUSE
1225 PRINT “Period:”; T; “s”: PAUSE
1230 END

Example:  L = 1.14 m
Results:  W = 2.932971967 m/s, T = 2.1422588902 s

TI-74 Secret 3 Digit Codes

I learn the PRINT USING and IMAGE commands for the first time here.  On the TI-74, # is a number field, the period (.) is the decimal point, ^ is the exponential character, and I can use spaces and text.  Yes, IMAGE is different on each of the basic calculators.

500  IMAGE ###   ###   (3 spaces in between the sets of hashtags)
505  PRINT “Here are the”: PAUSE 1
510  PRINT “secret codes!”: PAUSE 1
515  FOR I=1 TO 4
520 A=100*RND: B=100*RND
525 PRINT USING 500; A,B : PAUSE 1
530 NEXT I
540 END

Notes

1.     I am not able to use a variable while using a DIM command to size an array.  This is not allowed:

100 Z = 10
110 DIM A(Z)

2.     The commands and one-letter variables auto-capitalize when [ENTER] is pressed.  For example:

I type 100 print a, press [ENTER] and when look at the line again, the TI-74 displays:
100 PRINT A

3.     It is a good idea to put an END command after each routine.  END will tell the TI-74 stop, allowing multiple, separate routines in the TI-74 programming space.

4.    The amount of free memory is found by the formula:  FRE(0)-FRE(1).  The keyboard shortcut to FRE is [FN] [ ↓ ].

5.    If you want to clear the entire program space, type NEW ALL.

There will be more TI-74 programs in the near future.  Until next time,

Eddie


This blog is property of Edward Shore, 2016.

Monday, September 5, 2016

Retro: A Quick Look at the TI-74 (and HHC 2016)

Retro:  A Quick Look at the TI-74 Basicalc




Back to the 1980s Again

Recently I purchased a Texas Instruments TI-74 Basicalc calculator.  The calculator came in great condition, including manuals and a Mathematics module (and the module). 

The TI-74 is a BASIC programming calculator (similar to Hewlett Packard’s HP-71B and HP-75 and Casio’s fx-795P).  The keyboard of the TI-74 is very busy and has a QWERTY keyboard.  The keys are nice but I am not able to type fast on it.  The calculator takes four AAA batteries.  The calculator I got was produced in 1985.  The original cost was around $130, which was a pretty good price for a basic portable BASIC computer/calculator at the time.  

HP 71B (top) and TI-74 (bottom).  The 74 is a giant!


The TI-74 is a BASIC programming calculator (similar to Hewlett Packard’s HP-71B and HP-75 and Casio’s fx-795P).  The keyboard of the TI-74 is very busy and has a QWERTY keyboard.  The keys are nice but I am not able to type fast on it.  The calculator takes four AAA batteries.  The calculator I got was produced in 1985.  The original cost was around $110-$130, which was a pretty good price for a basic portable BASIC computer/calculator at the time.  The one I got on Amazon, originally sold at Brendle's (a defunct chain store which was based in Elkin, North Carolina)

Calculator Mode vs. BASIC Mode

Modes are switched back and forth with the [ MODE ] toggle key.

Calculator Mode

Like the HP-71B, the TI-74 has two modes: Calculator and BASIC mode.  In Calculator mode, the QWERTY keyboard becomes a scientific calculator, with all the functions stated in blue.  For example, the [ S ] key is the angle change key [ DRG ], while the [ U ] key becomes the square key [ x2 ].  In Calculator mode, the TI-74 operates as an AOS (Algebraic Operating System) calculator.  If have worked with a TI-30Xa or a classic TI-36X Solar, you should be familiar with it. 

The Display

The numbers are aligned to the right.  What is neat about the display is that the last function used will also be displayed.  For example:  cos(√19°):


Keys
Screen
[DRG] (S) to degrees mode
DEG is highlighted
19
19  |
[ √x ] (I)
4.358898944 | √x
[ cos ] (W)
.99710753 | cos


Two Argument Functions

One of the quirks about the Calculator mode is how two argument functions are operated.  For input, you will need to press [ (x,y) ] (the L key). 

Combinations and Permutations:  Enter n, press [ (x,y) ] (L), r and press either [ nCr ] (J) for combinations or [ nPr ] (H) for permutations. 

Polar to Rectangular:  Enter r, press [ (x,y) ] (L), then θ, [ P>R ] (F).  x is displayed first, press [x<>y] (RUN) to show y. 

Rectangular to Polar:  Enter x, press [ (x,y) ] (L), then y, press [ INV ] (SHIFT), [ P>R ] (F).  r is displayed first, press [x<>y] (RUN) to show θ. 

Strangely enough, this isn’t the percent change function works.  Enter the new amount, press [Δ%] (SPACE), then the old amount.  For example, if I wanted to find the percent change from 150 to 180, I would key in 180, [Δ%], 150, [ = ] to get 20. (20% increase)  This is also the same way of how to computer percent changes with the TI-55 III.

Statistics: Only Available in Calculator Mode

The statistics module of the TI-74’s calculator mode can handle either one-variable date or linear regression (y = a + bx).  You call statistical variables and clear its registers by first pressing the [ STAT ] (CTL) key.  All the statistical variables are marked in yellow.

BASIC Mode

By default, the TI-74 has 7,710 bytes of memory.  You can add a memory module that would affectively double the memory.  This is also where you can access any ROM module commands.

The language of the TI-74 is straight forward.  What is neat is that the case that comes with the TI-74 has syntax of the BASIC commands available card for reference. 

There is only one program space (similar to early keystroke calculators like TI-58C and HP-12) on which all the programming steps are shared, with no separate file management.  However, you are able to run the program space from any designated line number, so you can fit multiple routines on the TI-74.  You can designate the line numbers from 1 to 32766, and each line numbers can become multi-statement lines with the use of colons. (:)

 Over the course of the next month or so, I hope to post programs for the TI-74.  Here is one that I did as my first TI-74 routine (sum of f(x)):

100 INPUT “lower:”;L
105 INPUT “upper:”;U
110 T=0
115 FOR X=L TO U
120 GOSUB 150
125 T=T+F
130 NEXT X
135 PRINT “total=”;T:PAUSE
140 END
150 F=X^2   \\ or any f(X)
155 RETURN

Make sure all the routines have END, that stops execution.  The default case for the alpha keys in BASIC mode is lower case.  To get the upper case lock, press [SHIFT] [UCL]. 

The only thing I am not crazy about is that the BASIC functions are printed in gray and it can be hard to see when holding the TI-74 at different angles.

Mathematics Module

The Mathematics Module for the TI-74 is very sophisticated.  I haven’t had much time to play with the module, but the module provides the following functions:

* Complex functions (COMPF): Arithmetic, Logarithms, Powers, Trigonometric, Parts of the Rectangular and Polar forms.  This is really full-fledged, especially for complex numbers in the 1980s.

* Gamma Function (GAM)

* Polynomial Multiplication (POL):  This program calculates the coefficients of p(x) * q(x)

* Curve Analysis: Cubic Splines, Relative Minimum, Root Finder by either Bisection or Newton’s Method

* Calculus:  Convolution, Runge-Kutta (differential equations), Gauss Quadrature (integrals)

* Matrices: 3 x 3 systems including complex numbers, Matrices Utilities (addition, multiplication, inverse, simultaneous equation, determinant), Tridiagonal Solving routine

Peripherals

The TI-74 can be attached to a compatible printer or a module that allows programs to be recorded on cassettes. 
  

On a side note… HHC 2016!

I will be going to the HHC 2016 conference in two weeks (9/17 – 9/18/16) in Fort Collins, CO.


Eddie


This blog is property of Edward Shore, 2016.

RPN HP 12C: Fibonacci and Lucas Sequences

  RPN HP 12C: Fibonacci and Lucas Sequences Golden Ratio, Formulas, and Sequences Let φ be the Golden Ratio: φ = (1 + √5) ÷ 2...