Showing posts with label speed of sound in air. Show all posts
Showing posts with label speed of sound in air. Show all posts

Saturday, September 6, 2025

HP 71B Programs: September 2025

HP 71B Programs: September 2025


One of my favorite calculators/pocket calculators of all time is the HP 71B.



ADDMOD: (a + b) mod n = a mod n + b mod n


10 DESTROY A, B, N

20 DISP “(A+B) MOD N” @ WAIT .5

30 INPUT “A? “; A

40 INPUT “B? “; B

50 INPUT “C? “; C

60 S = MOD(A, N) + MOD(B, N)

70 S = MOD(S, N)

80 DISP “SUM = “; S


MULTMOD: (a * b) mod n = a mod n * b mod n


10 DESTROY A, B, N

20 DISP “(A*B) MOD N” @ WAIT .5

30 INPUT “A? “; A

40 INPUT “B? “; B

50 INPUT “N? “; N

60 P = MOD(A, N) * MOD(B, N)

70 P = MOD(P, N)

80 DISP “PRODUCT = “; P


Examples:

A

630

48

15

B

320

99

47

N

700

15

7

SUM:

250

12

6

PRODUCT:

0

12

5



GABLE: Area of a Gable Roof


10 DESTROY P, S, L

20 DEGREES

30 INPUT “PITCH (IN.)? “; P

40 INPUT “SPAN (FT.)? “; S

50 INPUT “LENGTH (FT.)? “; L

60 A = 2 * S * L / COS(ATAN(P/12))

70 DISP “AREA = “; A; “ FT^2”


Input: Pitch (P)

6”

3”

4”

Input: Span (S)

110” (110/12 ft)

5’ 8” (5 + 8/12 ft)

15 ft

Input: Length (L)

100” (100/12 ft)

10’

10 ft

Output: Area (A)

170.81074828 ft^2

116.821326059 ft^2

316.227766017 ft^2



INTENSE: Light Intensity of a Spherical or a Cylindrical Light Source


intensity = power / surface area

intensity (W/m^2), power (W), surface area (m^2)

Surface area: sphere = 4 * π * r^2, cylinder = 2 * π * (r * h + r^2)


10 DESTROY P, K$, R, H

20 DISP “INTENSITY OF LIGHT!” @ WAIT .5

30 INPUT “POWER (W)? “; P


40 DISP “1. SPHERE 2. CYLINDER”

50 DELAY 0,0

60 K$ = KEY$

70 IF K$ = “1” OR K$ = “S” THEN GOTO 100

80 IF K$ = “2” OR K$ = “C” THEN GOTO 200

90 GOTO 40


100 INPUT “RADIUS (M)? “; R

110 A = 4 * PI * R^2

120 GOTO 300


200 INPUT “RADIUS (M)? “; R

210 INPUT “HEIGHT (M)? “; H

220 A = 2 * PI * (R * H + R^2)

230 GOTO 300


300 I = P / A

310 DISP I; “W/M^2”


Examples:


Sphere: r = 4 m, Power = 60 W: Intensity = .298415518297 W/M^2


Cylinder: r = 1.25 m, h = 0.75 m, Power = 70 W; Intensity = 4.45633840656 W/M^2



SIMPLE: Simple Interest – Banker’s Rule


interest = amount * rate% / 100 * #days / 360

final = principal + interest (final, maturity value)


10 DESTROY P, R, I, M

20 DISP “SIMPLE INTEREST” @ WAIT .5

30 INPUT “AMT? “; P

40 INPUT “RATE%? “; R

50 INPUT “# DAYS? “; D

60 I = P * R * D / 360 / 100

70 M = P + I

80 IMAGE K, M10D.2D

90 DISP USING 80; “INT.=”, I @ PAUSE

100 DISP USING 80; “FINAL=”, M


Notes:


* When the HP 71B is in pause, press [ f ] [ + ] to continue (CONT).

* To stop execution, press [ ON ] (ATTN).

* IMAGE K, M10D.2D: display “prompt string”, number rounded to 2 decimal places. The number is right-justified, make the prompt string 7 characters or less to fit both the string and number on the screen.


Examples


Input: Amount

1500

2000

2800

Input: Rate %

4.00%

8.00%

6.65%

Input: # Days

180

90

60

Output: Interest

30

40

31.03

Output: Final

1530

2040

2831.03



AIRSOUND: Speed of Sound in Air


S = 331.5 + .606 * T

S = speed of sound in air, m/s

T = temperature in °C


10 DESTROY K$, S, T

20 DISP “SPEED OF SOUND IN AIR” @ WAIT .5

30 DISP “SOLVE FOR…” @ WAIT .5

40 DISP “1. SPEED 2. TEMP”

60 K$ = KEY$

70 IF K$=”1” OR K$=”S” THEN GOTO 100

80 IF K$=”2” OR K$=”T” THEN GOTO 200

90 GOTO 40


100 INPUT “TEMP (°C)? “; T

110 S = 331.5 + .606 * T

120 DISP “S=”; S; “ M/S”

130 END


200 INPUT “SPEED (M/S)? “; S

210 T = (S- 331.5) / .606

220 DISP “T=”; T ; “°C”

230 END



Examples:


Input: T = 74 °F = (32 + 1/3) °C

Output: S = 345.64 m/s

Input: S = 350 m/s

Output: T = 30.5280528053 °C

Input: T = -8.5 °C

Output: S = 326.349 m/s

Input: S = 382 m/s

Output: T = 83.3333333333 °C



Eddie


All original content copyright, © 2011-2025. 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.

The author does not use AI engines and never will.

Saturday, May 18, 2024

HP 15C and Python: Calculating The Speed of Sound in Air

 HP 15C and Python: Calculating The Speed of Sound in Air



How fast does Sound Travel?


We can calculate the speed of sound in air which depends on temperature.


The speed of sound in air can be approximated by:

c ≈ √( γ * R * T / M)


where:


R = molar gas constant = 8.314 4625 618 153 J/(K * mol)

R = 8.314 4625 618 153 (kg * m^2)/(s^2 * K * mol)


M = molar mass of air = 0.02897 kg/mol


γ = adiabatic index of air

The index of air varies between 1.3991 and 1.403. For calculations, Wikipedia uses an average value of γ = 1.4. (see Source). For reference, an adiabatic process is a thermodynamic process that does not use heat.


A joule is a composite unit, 1 J = 1 (kg * m^2)/s^2


T = temperature in Kelvin.


Convert temperatures to Kelvin:


Fahrenheit to Kelvin:

T = 5/9 * (°F – 32) + 273.15


Celsius to Kelvin:

T = °C + 273.15


A formula to calculate the speed of sound in air is:


C = √( γ * R * T / M)


Entering the three numerical constants for γ, R, M:


γ * R / M ≈ 401.8035093 m^2/(s^2 * K)


Then:


C ≈ √(401.8035093 * T)

≈ 20.04503702 * √T


A popular version of the formula can be achieved by multiplying by 273.15/273.15 (essentially multiplying by 1):


C ≈ √(401.8035093 * 273.15 * T / 273.15)

≈ √(401.8035093 * 273.15) * √(T / 273.15)

≈ 331.2893427 * √(T / 273.15)


Let °C be the temperature in degrees Celsius. Then:

≈ 331.2893427 * √((°C + 273.15) / 273.15)

≈ 331.2893427 * √(°C / 273.15 + 1)


The Wikipedia formula rounds the constant to 331.3. (see Source) Other formulas use 331.


However, we can use the formula


C ≈ 20.04503702 * √T


and be in the ballpark. Note we’ll have to convert the temperature to Kelvin before using this formula.




HP 15C (Collector’s Edition) Program: Speed of Sound


Instructions:


To calculate the speed of sound when the temperature is in Fahrenheit (°F), press [ f ] { A } or [ GSB ] { A } [ R/S ].


To calculate the speed of sound when the temperature is in Celsius (°C), press [ f ] { B } or [ GSB ] { B } [ R/S ].


To calculate the speed of sound when the temperature is in Kevin (K), press [ f ] { C } or [ GSB ] { C } [ R/S ].


Code


Step

Key Code

Key

Notes

001

42, 21, 11

LBL A

Enter °F, convert to °C

002

3

3


003

2

2


004

30

-


005

5

5


006

20

×


007

9

9


008

10

÷


009

42, 22, 12

LBL B

Enter °C, convert to K

010

2

2


011

7

7


012

3

3


013

48

.


014

1

1


015

5

5


016

40

+


017

42, 22, 13

LBL C

Enter K

018

11

Calculate Speed of Sound

019

2

2


020

0

0


021

48

.


022

0

0


023

4

4


024

5

5


025

0

0


026

3

3


027

7

7


028

0

0


029

2

2


030

20

×


031

36

ENTER


032

36

ENTER


033

2

2


034

48

.


035

2

2


036

3

3


037

6

6


038

9

9


039

3

3


040

6

6


041

20

×


042

34

X<>Y


043

43, 32

RTN

End of the program


Python Code: spsound.py


Programmed on a TI-84 Plus CE Python.


print("Speed Of Sound\n")

print("1. Fahrenheit")

print("2. Celsius")

print("3. Kelvin")


# type of temperature

# choice var must be an integer

# ch is used in an element call

ch=int(input("? "))

if ch==1:

t0=eval(input("deg F? "))

t=5/9*(t0-32)+273.15

elif ch==2:

t0=eval(input("deg C? "))

t=t0+273.15

elif ch==3:

t0=eval(input("K? "))

t=t0

else:

print("Not a valid choice")

# force an error to stop the script

1/0


# calculation

s1=20.04503702*t**0.5

s2=s1*2.236936

print(str(s1)+" m/s")

print(str(s2)+" mi/hr")




Example Calculations (rounded to 5 decimal places)


Temperature

Speed of Sound (m/s)

Speed of Sound (mi/hr)

68 °F

343.20358

767.72445

35 °C

351.87462

787.83024

280 K

335.41762

750.30776

0 °C

331.28934

741.07306

96 °F

352.19167

787.83024



Source


“Speed of Sound” Wikipedia. Last Edited March 27, 2024. https://en.wikipedia.org/wiki/Speed_of_sound Retrieved April 7, 2024



Until next time,


Eddie


All original content copyright, © 2011-2024. 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.

Retro Review: HP 65

Retro Review: HP 65 Quick Facts Company: Hewlett Packard Years: 1974 - 1977 Type: Scientific, RPN (Reverse Polish Notation) Mem...