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.