Showing posts with label area. Show all posts
Showing posts with label area. Show all posts

Saturday, May 16, 2026

Python (TI-84 Plus CE) and Swiss Micros DM32: The Integral of y = abs(r * x + s)

Python (TI-84 Plus CE) and Swiss Micros DM32: The Integral of y = abs(r * x + s)




The Integral of y = abs(r * x + s)



This algorithm calculates the integral of ∫ abs(r * x + s) dx, from x = a, x = b), where r and s are constants. For clarity, I am using abs to stand for absolute value instead of the customary pipe characters (|x|).



Let the function y = abs(r * x + s). Then the function can be defined as a piecewise function (without loss of generality):

y =

{ -(r * x + s), x < xc

{ (r * x + s), x ≤ xc



The point x = xc is the critical point because it is the root (zero) of this function:

abs(r * x + s) = 0

Because abs(0) = 0:

r * x + s = 0

r * x = -s

x = -s/r



and:

-(r * x + s) = 0

r * x + s = 0

x = -s/r



Let the critical point xc = -s/r



Taking the indefinite integral of y(x) yields:

∫ y(x) dx =

{ -r * x^2 ÷ 2 – s * x + C, x < xc

{ r * x^2 ÷ 2 + s * x + C, x ≥ xc

and C is an arbitrary integration constant.



Let f(x) = r * x^2 ÷ 2 + s * x and find the definite integral from x = a to x = b.



Case 1: a ≥ xc and b ≥ xc, where both a and b are greater than the critical point. This is the simplest case.



∫ ( r * x + s dx, x = a to x = b)

= (r * b^2 ÷ 2 + s * b) - (r * a^2 ÷ 2 + s * a)

= f(b) – f(a)



Case 2: a < xc and b < xc, both a and b are less than the critical point.

∫ ( r * x + s dx, x = a to x = b)

= -(r * b^2 ÷ 2 + s * b) - -(r * a^2 ÷ 2 + s * a)

= -(r * b^2 ÷ 2 + s * b) + (r * a^2 ÷ 2 + s * a)

= (-r * b^2 ÷ 2 - s * b) + (r * a^2 ÷ 2 + s * a)

= -f(b) + f(a)

= -(f(b) - f(a))



Combining cases 1 and 2, the area can be calculated as:

area = abs(f(b) – f(a))

with (a – xc) * (b – xc) ≥ 0



Case 3: a < xc and b ≥ xc

∫ ( r * x + s dx, x = a to x = b)

= ∫ ( -(r * x + s) dx, x = a to x = xc) + ∫ ( r * x + s dx, x = xc to b)

= -(r * xc^2 ÷ 2 + s *xc) + (r * a^2 ÷ 2 + s * a) + (r * b^2 ÷ 2 + s * b) – (r * xc^2 ÷ 2 + s * xc)

= -f(xc) + f(a) + f(b) – f(xc)

= f(a) – 2 * f(xc) + f(b)

Since area must be positive: abs(f(a) – 2 * f(xc) + f(b)).

Consequently: (a – xc) * (b – xc) < 0.



In summary:

Let xc = -r/s

If (a – xc) * (b – xc) ≥ 0: area = abs(f(b) – f(a))

Else if (a – xc) * (b – xc) < 0: area = abs(f(a) – 2 * f(xc) + f(b))

where f(x) = r * x^2 ÷ 2 + s * x



Please note: ∫ abs(r * x + s) dx ≠ abs(a * x^2 ÷ b * x)



TI-84 Plus CE Python Edition: abslin1.py



Programmed with TI-84 Plus CE Python, but can be used on any calculator with Python since only the math module is used.



# Math Calculations
from math import *

# Python Version
# 2026-01-05 EWS

print("integral of abs(rx+s)")
r=eval(input("r? "))
s=eval(input("s? "))
a=eval(input("lower limit? "))
b=eval(input("upper limit? "))

# critical point
c=-s/r

# integral
f=lambda x:r*x**2/2+s*x
f0=f(c)
f1=f(a)
f2=f(b)

if (a-c)*(b-c)>=0:
  t=abs(f2-f1)
else:
  t=abs(f1-2*f0+f2)

print("area = ",str(t))



Swiss Micros DM32 Program: asblin



Three labels are used: A (172 bytes), Z (20 bytes), Y (17 bytes), total 209 bytes

Text strings can be eliminated.



A01 LBL A

A02 SF 10

A03 “AREA ABS(RX +S)”

A04 INPUT R

A05 INPUT S

A06 x<>y

A07 ÷

A08 +/-

A09 STO C

A10 XEQ Y

A11 STO D

A12 “LOW=A HIGH=B”

A13 INPUT A

A14 XEQ Y

A15 STO E

A16 INPUT B

A17 XEQ Y

A18 STO F

A19 RCL B

A20 RCL- C

A21 RCL A

A22 RCL- C

A23 ×

A24 x≥0?

A25 GTO Z

A26 RCL E

A27 RCL D

A28 2

A29 ×

A30 -

A31 RCL+ F

A32 ABS

A33 STO Z

A34 CF 10

A35 RTN



Z01 LBL Z

Z02 RCL E

Z03 RCL- F

Z04 ABS

Z05 STO Z

Z06 CF 10

Z07 RTN



Y01 LBL Y (Note: f(x) = r*x^2 ÷ 2 + s*x)

Y02 ENTER

Y03 x^2

Y04 RCL× R

Y05 2

Y06 ÷

Y07 x<>y

Y08 RCL× S

Y09 +

Y10 RTN



Examples



Example 1:

y = abs(4 * x + 3)

r = 4, s = 3, xc = -0.75





Lower Limit (a)

Higher Limit (b)

Area

-4

5

87.25

-4

-1

21

0

5

65



Example 2:

y = abs(-3 * x + 6)

r = -3, s = 6, xc = 2



Lower Limit (a)

Higher Limit (b)

Area

-5

5

87

3

5

12

-5

1

72


Hope you find this helpful and have a great day,


Eddie


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

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, May 25, 2024

Swiss Micros DM32: Spherical Triangle ft. Law of Cosines

Swiss Micros DM32: Spherical Triangle ft. Law of Cosines



Introduction


The state file spheretri.d32 is about solving triangles on the spherical space.





The programs solve spherical triangles in two common problems: SSS (side-side-side, really arc lengths) and SAS (side-angle-side). All the inputs are in decimal degrees.


Also calculated are the surface area and perimeter, both in radians. The radius is assumed to be 1.


Surface Area = ( A° + B° + C° ) * Ï€ / 180 – Ï€ = A + B + C – Ï€


Perimeter = ( X° + Y° + Z°) * Ï€ / 180 = X + Y + Z


The sum of the angles (A, B, C) must be greater than 180° (Ï€ radians). Due to this requirement, in solving for angles and sides, the Law of Cosines will be used in each instance. The Law of Sines is only advised to check ratios.



Equation listing


Law of Sines – can be used as a check on triangles:

SIN(A)÷SIN(X)=SIN(B)÷SIN(Y)


Law of Cosines – two equations:

COS(Z)=COS(X)×COS(Y)+SIN(X)×SIN(Y)×COS(C)

COS(C)=-COS(A)×COS(B)+SIN(A)×SIN(B)×COS(Z)


Here the variables are general place holders.



Program Listing


Labels:

Label H: help program

Label I: Initialization routine. Sets the angles mode to degrees and clears the variables.

Label C: Starts the solve spherical triangle routine: given the three arc lengths X, Y, and Z.

Label Z: Starts the solve spherical triangle routine: given the arc lengths X and Y and and the angle between the arcs, angle C

Label F: Routine to solve for angles A and B, perimeter, and area



General Instructions


  1. To start a new problem, execute program I.

  2. To solve a spherical triangle given the sides (arc lengths), execute program C. (SSS)

  3. To solve a spherical triangle given two sides and the internal angle, execute program Z. (SAS)


This program also solves for the surface area, assuming a radius of 1, and perimeter of the triangle.


Program Code



H01 LBL H

H02 SF 10

H03 EQN: A N G L E _ A _ B _ C

H04 EQN: S I D E S _ X _ Y _ Z

H05 EQN: X E Q _ C _ S S S

H06 EQN: X E Q _ Z _ S A S

H07 EQN: E Q N S _ A R E _ S I N E

H08 EQN: A N D _ C O S I N E _ L A W S

H09 CF 10

H10 RTN


I01 LBL I

I02 DEG

I03 CLVARS

I04 CLx

I05 RTN


C01 LBL C

C02 INPUT X

C03 INPUT Y

C04 INPUT Z

C05 RCL Z

C06 COS

C07 RCL X

C08 COS

C09 RCL Y

C10 COS

C11 ×

C12 -

C13 RCL X

C14 SIN

C15 RCL Y

C16 SIN

C17 ×

C18 ÷

C19 ACOS

C20 STO C

C21 VIEW C

C22 XEQ F

C23 RTN


Z01 LBL Z

Z02 INPUT X

Z03 INPUT Y

Z04 INPUT C

Z05 RCL X

Z06 COS

Z07 RCL Y

Z08 COS

Z09 ×

Z10 RCL X

Z11 SIN

Z12 RCL Y

Z13 SIN

Z14 ×

Z15 RCL C

Z16 COS

Z17 ×

Z18 +

Z19 ACOS

Z20 STO Z

Z21 VIEW Z

Z22 XEQ F

Z23 RTN


F01 LBL F

F02 RCL X

F03 COS

F04 RCL Z

F05 COS

F06 RCL Y

F07 COS

F08 ×

F09 -

F10 RCL Z

F11 SIN

F12 RCL Y

F13 SIN

F14 ×

F15 ÷

F16 ACOS

F17 STO A

F18 RCL Y

F19 COS

F20 RCL X

F21 COS

F22 RCL Z

F23 COS

F24 ×

F25 -

F26 RCL X

F27 SIN

F28 RCL Z

F29 SIN

F30 ×

F31 ÷

F32 ACOS

F33 STO B

F34 RCL A

F35 RCL+ B

F36 RCL+ C

F37 →RAD

F38 π

F39 -

F40 STO R

F41 RCL X

F42 RCL+ Y

F43 RCL+ Z

F44 →RAD

F45 STO P

F46 VIEW A

F47 VIEW B

F48 VIEW R

F49 VIEW P

F50 RTN


You can download the DM32 state file here:


https://drive.google.com/file/d/1qX-y2G5sCOmm4ktmZbnGoPI3uzrx6IfF/view?usp=sharing



Examples  (FIX 5)


SSS Problem (LBL C)


X = 18.66°

Y = 20.49°

Z = 19.95°


Results:

C = 62.04726°

A = 55.92702°

B = 64.98954°

R = 0.05173 radians (surface area)

P = 1.03149 radians (perimeter)


SAS Problem (LBL Z)


X = 17.00 °

Y = 23.32°

C = 64.55°


Results:

Z = 21.88733°

A = 45.08768°

B = 73.51096 °

R = 0.05495 radians (surface area)

P = 1.08572 radians (perimeter)



Sources


Wikipedia. “Spherical Triangle” Updated April 9, 2024. Retrieved April 11, 2024.

https://en.wikipedia.org/wiki/Spherical_trigonometry#:~:text=Spherical%20trigonometry%20is%20the%20branch,sphere%2C%20geodesics%20are%20great%20circles.


Gray, Glen. “Spherical Trigonometry – An Introduction and Basic Theorems” Video. February 12, 2023. Retrieved April 11, 2024. https://www.youtube.com/watch?v=McWv9bcvMYg



Note: The blog will be posted on Saturdays only on June and July 2024.


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.

Sunday, May 5, 2024

Circular Sector: Finding the Radius and Angle

 Circular Sector: Finding the Radius and Angle





Here is the problem:


We are given the area of the circular segment, A, and the arc length of the segment, s. What is the radius, r, and the angle, θ?


The arc length is calculated as: s = θ * r


The area is calculated as: A = ½ * θ * r^2


We have the system of equations:


A = ½ * θ * r^2

s = θ * r


Divide A by s:


A / s= (½ * θ * r^2) / (θ * r)

A / s = r / 2

2 * A / s = r


Then

s = r * θ

θ = s / r = s^2 / (2 * A)


In summary:

r = 2 * A / s

θ = s / r = s^2 / (2 * A)


Note that the angle is in radians.

Example


Example 1:

s = 4, A = 30


r = (2 * 30) / 4 = 15

θ = 4 / 15 ≈ 0.266666667


Example 2:

s = 10.5, A = 31.8


r = (2 * 30) / 4 = 212/35 ≈ 6.057142857

θ = 10.5 / (212/35) = 735/424 ≈ 1.733490566


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.

Python – Earth’s Radius and Gravity in US Units

Python – Earth’s Radius and Gravity in US Units Introduction The following script, gravus2.py, estimates the Earth’s gravity i...