Showing posts with label integration. Show all posts
Showing posts with label integration. 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.

Saturday, January 3, 2026

Comparison of Formula Evaluators: TI-60X, TI-68, Sharp EL-5150, fx-4200P, fx-5000f

Comparison of Formula Evaluators


Happy New Year! Let’s start the new year by comparing formula evaluator calculators. The calculators featured are:


TI-60X (early 1990s)


TI-68 (late 1980s/1990s)


Sharp EL-5150 (late 1970s/early 1980s)


fx-4200P (late 1980s/early 1990s)



fx-5000f (late 1980s/early 1990s)


Formula evaluator: A calculator which strictly evaluates simple formulas. There are no loops, no solvers, no sums. The formula evaluates to one answer but can have more than one inputs.


Example:

Allowed: f(x) = x² + 3 – 1 / x

Allowed: f(a,b) = (a * b) / (a + b)

Not Allowed: f(x) = Σ(x² / 3, x = 0, 10)

Not Allowed: f(x) = [1 if x ≥ 0, else 0]



TI-60X

TI-68

Sharp EL-5150

fx-4200P

fx-5000F

Battery

1 x CR2032

1 X CR2032

3 x SR44/LR44

1 x CR2032

2 x CR2032

Memory (bytes)

12 registers (84 bytes)

55 registers (440 bytes)

80 steps

279 steps

675 steps

Variables: Number and Type

12, Single letter: A through I, X, Y, Z

Up to three character variables (3 character variables take up 2 registers)

11: A – J, M

26 single letters for formulas only: A – Z; 6 separate numerical constants (K1-K6)

Letters and Greek characters for formulas only; separate numerical constants (K0-K9)

Does store values to variables take space?

Yes, each variable takes up a register

Yes, 1 register for 1 or 2 character variables, 2 for 3 character variables

No

No

No

How Formulas are accessed

[ 2nd ] [ EE ] (FMLA)

[ 2nd ] [ EE ] (FMLA)

AER Mode; up to 5 lines

[ IN ]/[ OUT ]

[ MODE ] 2: WRT

Prog 0-9,A,B: 12 slots

Integration?

∫ f(x) dx

Yes

Yes

No

No

No

Base conversions?

Yes, with Boolean logic

Yes, with Boolean logic

No

Yes, 32 bit binary block

No

Complex numbers?

No

Yes, with trig and log complex calculations

No

No

No

Engineering symbols?

No

No

Display toggle switch

Display toggle switch

Display toggle switch

Conversions?

Yes. 4 pairs (in/cm, gal/L, lb/kg, °F/°C)

Yes. 4 pairs (in/cm, gal/L, lb/kg, °F/°C)

No

No

No

Scientific Constants?

No

No

No

No

Yes ([ALPHA] [ ln ] (CONST)), 13


Other


Special 13 digit precision mode

Landscape form


128 built in formulas



The four pairs of conversions included in the TI-60X and TI-68 are:

in/cm: inches/centimeters

gal/L: gallons/liters

lb/kg: pounds/kilograms

°F/°C: degrees Fahrenheit/degrees Celsius


The scientific constants included on the fx-5000F are:

c: Speed of Light

h: Planck’s Constant

G: Universal Gravitational Constant

e: Elementary Charge

me: Electron Mass

u: Atomic Mass Unit

k: Boltzmann Constant

Vm: Molar Volume of Ideal Gas at Standard, Temperature, and Pressure

g: Earth’s Gravity Constant

R: Molar Gas Constant

ε0: Permittivity of Vacuum

µ0: Permeability of Vacuum


All the constants are in SI units.


Out of the calculators listed, my favorites are the TI-68 and fx-5000F.



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, November 15, 2025

Basic (TI-81) vs. Python (TI-84 Plus CE Python): First and Second Derivative and Integral by Simpson’s Rule

Basic vs. Python: First and Second Derivative and Integral by Simpson’s Rule



Calculators Used


Basic: TI-81

Python: TI-84 Plus CE Python



Task


Estimate the numerical first derivative by the Nearby Secant Line Method:


f'(x) = lim (f(x + h) - f(x - h)) / (2 * h) as h → 0



Estimate the numerical second derivative by:


f''(x) = lim (f(x + h) - 2 * f(x) + f(x - h)) / h^2 as h → 0



Estimate the definite integral by Simpson’s rule:


∫( Y1 dx, x = a to x = b) ≈

(b - a)/(3 * n) + (f(a) + 4 * f1 + 2 * f2 + 4 * f3 + 2 * f4 + ... + 2 * f_n-2 + 4 * f_n-1 + f(b))


n must be an even integer.

fi = f(a + i * (b – a) / n)


BASIC: TI-81


First let’s look at the TI-Basic version with the classic TI-81:


First Order Derivative  (Nearby Secant Line Method)


f'(x) ≈ (f(x + h) - f(x - h)) / (2 * h)


DER1  (61 bytes)

Function

Rad

Disp "D/DX Y1"

1E-4 -> H

Disp "X?"

Input A

A+H -> X

Y1 -> D

A-H -> X

(D-Y1)/(2H)->D

Disp D



Second Order Derivative


f''(x) ≈ (f(x + h) - 2 * f(x) + f(x - h)) / h^2


DER2  (75 bytes)

Function

Rad

Disp "D²/DX² Y1"

1E-4 -> H

Disp "X?"

Input A

A+H -> X

Y1 -> D

A -> X

D-2*Y1 -> D

A-H -> X

(D+Y1)/(H^2) -> D

Disp D


INTGY1  (134 bytes)

Function 

Rad

Disp "SIMPSONS RULE"

Disp "A,B,N?"

Input A

Input B

Input N

A -> X

Y1 -> S

B -> X

S+Y1 -> S

1 -> I

Lbl 1

A+I*(B-A)/N -> X

S+2*Y1 -> S

If Fpart (I/2)≠0

S+2*Y1 -> S

IS>(I,N-1)

Goto 1

S*(B-A)/(3*N) -> S

Disp S


Examples


f(x) = 3*x^3 + 4*x – 1


Y1 = 3 * X³ + 4 * X – 1

f’(2.4): DER1 returns: 55.84

f’’(2.4): DER2 returns: 43.2


∫( 3 * X³ + 4 * X – 1 dX, 0.5, 1.5):

INTGY1 returns with N = 40 returns 6.75


Notes for BASIC


Before running the programs, store the function to the variable Y1. Calling Y1 evaluates the function of the value stored in variable X. Evaluate Y1 at X: [2nd], (Y-VARS), 1


The TI-81 MUST be in Function mode to evaluate Y1, unless an error occurs. The programs set the angle mode to Radians. The value of h is set to a "default" value of 10^-4. We want h to be small, but not too small. A value of h too small can run the risk of floating point errors.


In the integral program:


* I/2 - Ipart (I/2) is Fpart(I/2), but the long way. Python does not have a built-in fractional part function.


* IS>(I,N-1) translates to:


I=I+1

If I>N-1

Goto 1


IS> is the increment (by 1) and skip, a command in TI-Calculator Basic.


In general BASIC languages, evaluation Y1 may take a different approach, depending on the calculator, pocket computer, or computer:


General Basic:


### ...

### X = g(A)

### GOSUB ***

### ...


*** Y = <evaluate f(X)>

*** RETURN


Another approach on a calculator: Use another program


Prog <main>

...

g(A) -> X

Prog "FX" (see below, answer is stored in Y)

...


Prog "FX" (or any name of your choosing)

<evaulate f(X)> -> Y

<end program, an implied Return is executed here>



PYTHON: TI-84 Plus CE Python Edition


The code presented here uses the math module and built-in functions, and should work with any calculator with Python.


DERINTG.py


from math import *

# derivatives and integrals

# 2025-06-01


print("MATH MODULE IS IMPORTED")


# first derivative function

def der1(fx,x,h=1E-3):

  # fx is a string

  # h is optional (def 1E-3)

  # set up lambda

  f=eval("lambda x:"+fx)

  d=(f(x+h)-f(x-h))/(2*h)

  return d


# second derivative function

def der2(fx,x,h=1E-3):

  # fx is a string

  # h is optional (def 1E-3)

  # set up lambda

  f=eval("lambda x:"+fx)

  d=(f(x+h)-2*f(x)+f(x-h))/(h**2)

  return d


# integrals by simpsons rule

def intg(fx,a,b,n=64):

  # fx is a string

  # n is even, optional (def 64)

  # set up lambda

  f=eval("lambda x:"+fx)

  s=f(a)+f(b)

  for i in range(1,n):

    w=f(a+i*(b-a)/n)

    s+=(2*w) if (i/2-int(i/2)==0) else (4*w)

  s*=(b-a)/(3*n)

  return s


I decided to make a script of three functions.


Python uses binary arithmetic, so be prepared to possibly see answers such as 2.999999999999 and 5.00000000000001. The code leaves the answer in floating point form. Feel free to use the round function and/or format specifiers as you see fit.


f(x) = 3*x^3 + 4*x – 1


In Python:

f(x) = 3*x**3+4*x-1


Examples


Store the string to s:

s=”3*x**3+4*x-1”

der1(s,2.4) returns 55.84000299999303

der2(s,2.4) returns 43.19999999324864

intg(s,0.5,1.5) returns 6.75



I hope you find this useful. Enjoy,


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.

Sharp EL-5200/EL-9000 AER II Program Collection – September 2026

Sharp EL-5200/EL-9000 AER II Program Collection – September 2026 For my review on the Sharp EL-5200 (also known as the Sharp EL-9000)...