Showing posts with label HP 71B. Show all posts
Showing posts with label HP 71B. Show all posts

Sunday, September 7, 2025

Basic vs. Python: Circle Inscribed in Circle [HP 71B, Casio fx-CG 100]

Basic vs. Python: Circle Inscribed in Circle



Calculators Used:

Basic: HP 71B

Python: Casio fx-CG 100


Introduction






Let a rectangle with sides A and B be inscribed in a circle. The circle has a radius R. Let the line segments with the length A have a corresponding angle Θ. If we are given R and Θ, we can use the chord length formula to calculate A and B.


The angle corresponding with side B can be determined as:

φ: angle corresponding with side B


φ + Θ + φ + Θ = 360°

2 × (φ + Θ) = 360°

φ + Θ = 180°

φ = 180° - Θ


Chord length:


A = 2 × R × sin(Θ/2)

B = 2 × R × sin(φ/2) = 2 × R × sin((180° - Θ)/2)


Knowing A and B, we can calculate the following:


Area of the rectangle = A × B

Area of the shaded area (circle – rectangle) = π × R^2 – A × B



Basic: HP 71B – INSCRECT


10 DESTROY R,A,B,C,D,T

15 DEGREES @ FIX 5

20 DISP “RECT. INSCR. CIRCLE” @ PAUSED

25 DISP “DEGREES MODE” @ WAIT 0.5

30 INPUT “RADIUS? “; R

35 INPUT “ANGLE-SIDE A? “; A


50 A = 2 * R * SIN(T/2)

55 B = 2 * R * SIN((180 – T)/2)

60 C = A * B

65 D = R^2 * PI – C


80 DISP “SIDE A = “, A @ PAUSE

85 DISP “SIDE B = “, B @ PAUSE

90 DISP “RECT ANGLE = “, C @ PAUSE

95 DISP “CIRC-RECT = “, D @ PAUSE

98 STD



Notes:

* FIX 5: Fix 5 display

* STD: Standard mode, floating point display

* DEGREES: Sets the HP 71B in degrees mode



Python: Casio fx-CG 100, insecrect.py



from math import *

print(“Rectangle Inscribed in a Circle”)

print(“Math module imported”)

r=eval(input(“Radius? “))

print(“Enter angle in degrees”)

t=eval(input(“Angle- A? “))

u=t*pi/180

a=2*r*sin(u/2)

b=2*r*sin((pi-u)/2)

c=a*b

d=r**2*pi-c

print(“A: {0.5f}”.format(a))

print(“B: {0.5f}”.format(b))

print(“Rect. Area: {0.5f}”.format(c))

print(“CIRC-AREA: {0:.5f}”.format(d))



Notes:

* Since the math module is used, this script can be used in any calculator with Python.

* Python’s angle mode is always in radians.



Examples



Example 1:

Inputs:

r = 10

Θ = 30°

Outputs:

a ≈ 5.17638

b ≈ 19.31852

c = 100

d ≈ 214.15927



Example 2:

Inputs:

r = 20

Θ = 80°

Outputs:

a ≈ 25.71150

b ≈ 30.64178

c ≈ 787.84620

d ≈ 468.79086



Example 3:

Inputs:

r = 20

Θ = 90°

Outputs:

a ≈ 35.35534

b ≈ 35.35534

c = 1250

d ≈ 713.49541



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, 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, July 19, 2025

HP 71B and HP Prime Python: Gaussian Quadrature

HP 71B and HP Prime Python: Gaussian Quadrature


A Very Brief Introduction


This is a top-level overview of the Gaussian Quadrature method. For more details, please check out the Sources section.


The design of GQ is to calculate:


∫( f(x) dx, -1, 1) ≈ Σ( wi * f(xi), i = 1, n)


Where do xi and wi come from?


* The xi values come from find the roots of the polynomials P’(x)= 0


* Pn’(x) are the derivatives of the Legendre polynomials Pn(x)


* After getting the roots, xi, the weights, w are calculated by the formula:

wi = 2 / ((1 -xi)^2 * Pn’(xi)^2)


Weights and Points of orders 3 and 5:


Among 3 points:

Roots (x) come from the derivative of the Legendre polynomial of the 3rd order.


Pn’(x) = 3/2 * (5*x^2 – 1)


Point xi

Weight wi

-√(3/5) ≈ -0.7745 9669 2 = -√0.6

5/9

0

8/9

√(3/5) ≈ 0.7745 9669 2 = √0.6

5/9


Among 5 points:

Roots (x) come from the derivative of the Legendre polynomial of the 5th order.


Pn’(x) = 15/8 * (21*x^4 – 14*x^2 + 1)


Point xi

Weight wi

-0.90617 98459

0.23692 68851

-0.53846 93101

0.47862 86705

0

128/225 ≈ 0.56888 88889

0.53846 93101

0.47862 86705

0.90617 98459

0.23692 68851



We can fit any interval [a, b] by this conversion:


∫( f(x) dx, a, b) = (b – a) / 2 * ∫( f( (b – a) / 2* x + (b + a) / 2 dx, -1, 1)


= (b – a) / 2 * Σ( wi * f( (b – a) / 2 * xi + (b + a) / 2 ), i = 1, n)


However, the programs on this blog entry will focus on the basic version of the Gaussian Quadrature.


The Code


The following code works with the following integrals:


∫( f(x) dx, -1, 1) ≈ Σ( wi * f(xi), i = 1, n)


HP 71B Basic


HP 71B: GQ3 (Gaussian Quadrature – 3 Point: Integrals from -1 to 1)


10 DEF FNF(X) = insert function of X here

15 S = 0

20 RADIANS

25 FOR I = 1 TO 3

30 READ X, W

31 DATA -SQR(0.6),5/9

32 DATA 0,8/9

33 DATA SQR(0.6),5/9

40 S = S + W * FNF(X)

55 NEXT I

50 DISP “ INTEGRAL= ”; S


HP 71B: GQ5 (Gaussian Quadrature – 5 Point: Integrals from -1 to 1)


10 DEF FNF(X) = insert function of X here

15 S = 0

20 RADIANS

25 FOR I = 1 TO 5

30 READ X, W

31 DATA -.9061798459, .2369268851

32 DATA -.5384693101, .4786286705

33 DATA 0, 128/255

34 DATA .5384693101, .4786286705

35 DATA .9061798459, .2369268851

40 S = S + W * FNF(X)

45 NEXT I

50 DISP “ INTEGRAL= ”; S



Integral Test: ∫( f(x) dx, -1, 1) ≈ Σ( wi * f(xi), i = 1, n)



Function f(x)

Actual (approx)

Gaussian 3 point (GQ3)

Gaussian 5 point (GQ5)

(x-3)*(x+4)*(x-5)

352/3 ≈ 117.333333333

117.333333333

117.333333334

-x^2 + 9*x + 10

58/3 ≈ 19.33333333

19.3333333334

19.3333333333

1.5 * cos(x)

2.524412954

2.52450532159

2.52441295561

exp(-x)

2.350402387

2.35033692868

2.35040238646

exp(sin(x))

2.283194521

2.28303911433

2.28319665353

sin(x)

0

0

0

1/(x - 2)

-1.09861228867

-1.09803921569

-1.09860924181



HP Prime Python App


HP Prime Python: gq3.py


# Gaussian Quadrature 3 point


from math import *


def f(x):

  # insert Function here

  return 1/(x-2)


s=0

x=[-sqrt(0.6),0,sqrt(0.6)]

w=[5/9,8/9,5/9]

for i in range(3):

  s=s+w[i]*f(x[i])


print("Integral: ",s)



HP Prime Python: gq5.py


# Gaussian Quadrature 5 point


from math import *


def f(x):

  # insert Function here

  return sin(x)


s=0

x=[0,-.5384693101056831,.5384693101056831,-.9061798459386640, .9061798459386640]

w=[.5688888888889,.4786286704993665,.4786286704993665,.2369268850561891,.2369268850561891]

for i in range(5):

  s=s+w[i]*f(x[i])


print("Integral: ",s)


Function f(x)

Actual (approx)

Gaussian 3 point (GQ3)

Gaussian 5 point (GQ5)

(x-3)*(x+4)*(x-5)

352/3 ≈ 117.333333333

117.333333333

117.333333333

-x^2 + 9*x + 10

58/3 ≈ 19.33333333

19.3333333333

19.3333333334

1.5 * cos(x)

2.524412954

2.52450532159038

2.52441295561081

exp(-x)

2.350402387

2.35033692868001

2.35040238646284

exp(sin(x))

2.283194521

2.2830391143268

2.28319665352905

sin(x)

0

0.0

0.0

1/(x - 2)

-1.09861228867

-1.09803921568627

-1.09860924181248


Sources


Kamermans, Mike “Pomax”. “Gaussian Quadrature Weights and Abscissae” https://pomax.github.io/bezierinfo/legendre-gauss.html 2011. Retrieved January 19, 2025.


Wikipedia. “Gauss-Legendre quadrature” https://en.wikipedia.org/wiki/Gauss%E2%80%93Legendre_quadrature Last edited January 19, 2025. Retrieved January 19, 2025.


Wikipedia. “Legendre Polynomials” https://en.wikipedia.org/wiki/Legendre_polynomials Last edited December 4, 2024. Retrieved January 19, 2025.



When it comes to evaluating integrals numerically, is Gaussian Quadrature better than Simpson’s Method?


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 content on this blog is 100% generated by humans. The author does not use AI engines and never will.



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...