Sunday, June 8, 2025

HP Prime and TI-84 Plus CE Python: Quartiles of a Data Set

HP Prime and TI-84 Plus CE Python: Quartiles of a Data Set



25th, 50th, and 75th Percentiles


The following code finds five points of a list of data points:


Minimum: the data point of least value

Q1: the first quartile, known as the 25th percentile. The first quartile is median of the lower half of the data.

Median: also known as the 50th percentile, this is the median, or middle point of the data.

Q3: the third quartile, known as the 75th percentile. The third quartile is the median of the upper half of the data.

Maximum: the data point of the most value


The list of data is first sorted in ascending order.


The median is determined as follows:


If the number of data points is odd: Take the number that lies in the middle.

If the number of data points is even: Take the average of the middle two numbers.


The way quartile values are determine vary depending by country and jurisdiction. The program presented uses Method 1, which is used in the United States. (see Source)


If the number of data points is odd: The data is split in half, do not include the median.

If the number of data points is even: The data is split in half.



Python File: quartiles.py, quartile.py


This script does not use any module, so it should work on every calculator that has Python, along with the full-computer editions of Python. Results are shown as floating point numbers, rounded to 5 decimal places.


This was code was made with the HP Prime emulator, and was tested on with an HP Prime, a TI-84 Plus CE Python edition, and a TI-83 Premium CE Python Edition calculator.


# quartiles program

# method 1, median divides data in half

# is used (US method)


# halfway subroutine

def halfway(l):

  n=len(l)

  # get halfway point

  # Python index starts at 0

  h=int(n/2)

  # even

  if n%2==0:

    return(l[h]+l[h-1])/2

  # odd 

  else:

    return(l[h])


print("Use list brackets. [ ]")  

data=eval(input("List of Data: "))


# length of the list

nw=len(data)


# sort the list

data.sort()

print("Sorted Data: "+str(data))


# maximum and minimum

q0=min(data)

q4=max(data)


# get sublists 

h=int(nw/2)

if nw%2==0:

  l1=data[0:h]

  l3=data[h:nw]

else:

  l1=data[0:h]

  l3=data[h+1:nw]


# list check

print("1st half: "+str(l1))

print("2nd half: "+str(l3))

  

# quartiles, q2 is the median

q1=halfway(l1)

q2=halfway(data)

q3=halfway(l3)


# set up  answer strings

txt1=["min = ","Q1 = ","median = ", 

"Q2 = ","max = "]

results=[q0,q1,q2,q3,q4]

for i in range(5):

  txt2="{0:.5f}"

  print(txt1[i]+txt2.format(results[i]))




Examples


Data Set: [1, 2, 3, 4, 5]

Min = 1.00000

Q1 = 1.50000

Med = 3.00000

Q3 = 4.50000

Max = 5.00000



Data Set: [76, 46, 49, 46, 56, 52, 59, 130, 80]

Min = 46.00000

Q1 = 47.50000

Med = 56.00000

Q3 = 78.00000

Max = 130.00000


Date Set: [55, 35, 40, 50, 60, 50, 55]

Min = 35.00000

Q1 = 40.00000

Med = 50.00000

Q3 = 55.00000

Max = 60.00000


Note: A Way to Format Numbers


To format numbers to have a set number of decimal places, use the code

{ identifier : .5f }.


The identifier can be almost anything, I usually call it 0 for the 1st number to be formatted. The number before the “f” (floating point indicator) is the number of decimal places. For example:


2 decimal places: { identifier : .2f }

5 decimal places: { identifier : .5f }

(spaces added for readability)


The text string will need to have a .format(arg) at the end of the string.


Example code:

n = 14.758119

txt = “The rounded value is {0:.5f}”

print(txt.format(n))


returns 14.75812


Source

Wikipedia. “Quartile” Last edited on February 21, 2025. https://en.wikipedia.org/wiki/Quartile Accessed May 12, 2025.



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.

Saturday, June 7, 2025

TI-84 Plus CE: Birefringence

TI-84 Plus CE: Birefringence


Introduction


Essentially, birefringence is the double refraction of light in material, drive by the differences in the refractive indices of both materials. Mathematically, birefringence between two materials is defined as:


B = | n_e – n_o |


n_o: refractive index of light where the ordinary ray originates

n_e: refractive index of light where the extraordinary ray originates


If n_e > n_o, we have positive birefringence, and the wave polarizes quickly.

If n_e < n_o, we have negative birefringence, and the wave polarizes slowly.


The relative retardation (delay or angle in radians) with one ray respected to another is calculated by the equation:


R = T * B


T = the thickness of the material, typically in meters



The program features 10 common materials, with the 11th allowing the user to enter their own refractive index, particularly useful for crystals.



TI-84 Plus CE Program: BIREF


Full

{1,1.000293,1.000132,1.333,1.31,1.46,1.49,1.52,1.69,2.417}→L₁

“ORDEXT”→Str0


For(I,1,2)

ClrHome

Output(9,1,"BIREFRINGENCE")

Output(3,1,"1. VACUUM")

Output(4,1,"2. AIR")

Output(5,1,"3. HYDROGEN")

Output(6,1,"4. WATER")

Output(7,1,"5. ICE")

Output(3,12,"6. QUARTZ")

Output(4,12,"7. PLEXIGLASS")

Output(5,12,"8. WINDOW GLASS")

Output(6,12,"9. FLINT GLASS")

Output(7,12,"10. DIAMOND")

Output(8,12,”11. YOUR OWN”)

Input sub(Str0,3(I-1)+1,3)+” RAY? ”,J


If J=11:Then:

Input “ENTER REF INDEX: “,X

If I=1:Then:X→O

Else:X→E:End

Else

If I=1:Then:L₁(J)→O

Else:L₁(J)→E:End

End

End


Input "THICKNESS? ",T

abs(E-O)→B

T*B→G


ClrHome

If E≥O:Then:Disp "POSITIVE"

Else:Disp "NEGATIVE":End

Disp "BIREFRINGENCE:",B,"DELAY:",G


Note: The Full mode sets the TI-84 to full screen mode.



Examples


Example 1: Diamond (ordinary ray) to Air (extraordinary ray), 0.5 m thick

Negative Birefringence: 1.416707

Delay: 0.7083535 (radians)



Example 2: Air (ordinary ray) to Ice (extraordinary ray), 3.6 m deep


Positive Birefringence: 0.309707

Delay: 1.1149452 (radians)



Sources


Nikon with contributing authors Douglas B. Murphy, Kenneth R. Spring, Thomas J. Fellers, and Michael W. Davidson. “Principles of Birefringence: Introduction to Optical Birefringence” Nikon. MicroscopyU: The Source for Microscopy Education. 2024/2025. Retrieved November 16, 2024. https://www.microscopyu.com/techniques/polarized-light/principles-of-birefringence#:~:text=Birefringence%20is%20formally%20defined%20as,dependent%20differences%20in%20refractive%20index.


“Refractive index.” Wikipedia https://en.wikipedia.org/wiki/Refractive_index At the time of retrieval, it was edited November 17, 2024. Retrieved December 1, 2024.



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.

Saturday, May 31, 2025

Casio fx-991CW: Recurrence Sequences

Casio fx-991CW: Recurrence Sequences



Introduction


Today’s edition we will work with recurring sequences, which can take the form of:


u_n = f(u_n-1), with initial condition u0


u_n = f(u_n-1, u_n-2) with initial conditions u0, u1


In general:


u_n = f(u_n-1, u_n-2, … u_n-k) with initial conditions u0, u1, u2, …, u_n-(k-1)


There is no app on the Casio fx-991CW that is dedicated to be recurrence sequences.



Recurring Sequences the Quick and Easy Way with the Calculate App


A quick way to tackle recurrence sequences and involves the use of the last answers key ( [Ans] ). This works on recurrence sequences with only one initial condition, u0.


Start by entering u0 and press [ EXE ]. Then enter the recurrence function, using Ans as u_(n-1).


Example:

u_n = 0.75 * u_(n-1)^2 + 1.03 * u_(n-1) with u0 = 1


Settings: MathI/DecimalO (Input/Output), Number Format (Norm 1)


1 [ EXE ]


0.75×Ans²+1.03×Ans [ EXE ] (Disp: 1.78)

[ EXE ] (Disp: 4.2097)

[ EXE ] (Disp: 17.62717157)

[ EXE ] (Disp: 251.1938698)

[ EXE ] (Disp: 47582.49986)


Recurrence Sequences with the Spreadsheet App


A way to generate recurrence sequences is to use the Spreadsheet app. The app contains a spreadsheet of size 5 columns (A, B, C, D, E) by 45 rows. Depending on the number of the initial conditions, up to 44 terms can be generated.


For the purposes of this blog, we’ll use column A, but we can use any column, as long as there is memory in the Spreadsheet.


u_n = f(u_n-1), with initial condition u0


Set A1 as the value of u0.

At cell A2:

1. Press [ TOOLS ].

2. Select Fill Formula and press [ OK ].

3. Enter the recurrence function, using A1 as u_(n-1).

4. At the range, set as A2:A#, to create a list of #-1 terms. For example, the range A2:A11 to create a list of 10 terms.

5. Select Confirm and press [ OK ].


Example:


Under Show Cell, Value (using the [TOOLS] menu)


u_n = (u_(n-1) + 0.5) * u_(n-1) with u0 = 0.65 for 7 terms.


Cell A1 = 0.65

Cell A2:

Fill Formula:

Form = (A1+0.5)×A1

Range: A2:A8



A (display)

1

0.65

2

0.7475

3

0.93250625

4

1.335821031

5

2.452328343

6

7.240078475

7

56.03877556

8

3168.363754



u_n = f(u_n-1, u_n-2), with initial condition u0, u1


Set A1 as the value of u0.

Set A2 as the value of u1.

At cell A3:

1. Press [ TOOLS ].

2. Select Fill Formula and press [ OK ].

3. Enter the recurrence function, using A1 as u_(n-2) and A2 as u_(n-1).

4. At the range, set as A3:A#, to create a list of #-2 terms. For example, the range A2:A11 to create a list of 9 terms.

5. Select Confirm and press [ OK ].


Example:


u_n = u_(n-1) + u_(n-2), u0 =1 , u1 = 1 for 7 terms.

Yes, this is ripe for the Fibonacci sequence.


Cell A1 = 1

Cell A2 = 1

Cell A3:

Fill Formula:

Form = A1+A2

Range: A3:A9



A (display)

1

1

2

1

3

2

4

3

5

5

6

8

7

13

8

21

9

34



Until next time,


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.

Saturday, May 24, 2025

TI-55 (1977) Programs: Illumination, Wind Turbine, Mile/Kilometer Conversion, 2D Vectors

TI-55 (1977) Programs: Wind Turbine, Mile/Kilometer Conversion, 2D Vectors


Time for the classic TI-55 calculator from the 1970s. My spotlight on this calculator from November 2024: https://edspi31415.blogspot.com/2024/11/spotlight-ti-55-from-1977.html


TI-55: Power Generated by a Wind Turbine


The power generated by a wind turbine can be calculated by:


P = (π * r²) / 2 * ρ * v³ = area / 2 * ρ * v³


P = power generated by the wind turbine (W, Watts)

r = length of an arm of the turbine (radius) (m)

ρ = density of air (kg/m³). Typically, ρ = 1.225 kg/m³

v = velocity of the air (m/s)


Inputs before running the program:

r STO 1, R1 = r

v STO 2, R2 = v

ρ STO 3, R3 = ρ


Note: This formula and program does not take efficiency factors into account. The theoretical maximum power is calculated.


Code:


Step

Key Code

Key


Step

Key Code

Key

00

49

π


10

02

2

01

55

×


11

35

y^x

02

61

RCL


12

03

3

03

01

1


13

45

÷

04

32


14

02

2

05

55

×


15

85

=

06

61

RCL


16

86

R/S

07

03

3


17

87

Rst

08

55

×





09

61

RCL






Examples:


r → R1

v → R2

ρ → R3

Result (P):

5

7

1.225

16500.234

6.1

13.3

1.225

168449.82

4

10

1

25132.741


Sources:


Sharp Electronics Corporation Conquering The Sciences: Applications for the SHARP Scientific Calculator EL-506A Sharp Corporation. Osaka, Japan. 1986. pp.75-77


Wind Turbine Calculator – Calculating Wind Turbine Power Output” CTRLCalculator.com 2024. Retrieved December 5, 2024. https://ctrlcalculator.com/ecology/wind-turbine-calculator/





TI-55: Miles/Kilometers Conversions


This program uses the in⋅mm conversion function. The results are stored as follows:


R1: x mi to km (first result)

R2: x km to mi (second result)


1 km ≈ 0.6213712 mi

1 mi ≈ 1.609344 km


Code:


Step

Key Code

Key


Step

Key Code

Key

00

51

STO


14

76

Prod

01

01

1


15

01

1

02

51

STO


16

21

INV

03

02

2


17

76

Prod

04

06

6


18

02

2

05

03

3


19

61

RCL

06

03

3


20

01

1

07

06

6


21

86

R/S

08

00

0


22

61

RCL

09

67

in⋅cm


23

02

2

10

45

÷


24

86

R/S

11

06

6


25

87

Rst

12

29

10^x





13

85

=






Examples:


X

R1: X mi → km

R2: X km → in

55

88.51392

34.17542

103

165.7624

64.00123

24.75

39.831264

15.378937



TI-55: 2D Vectors: Norm and Dot Product


Let there be two vectors defined as: [R1, R2] and [R3, R4].


Norms:

| [ R1, R2] | = √(R1² + R2²): stored in R5

| [ R3, R4] | = √(R3² + R4²): stored in R6


Dot Product:

[ R1, R2 ] ⋅ [ R3, R4 ] = R1 * R3 + R2 * R4


This program takes all 32 steps available on the TI-55. When this program terminates, the number in the display flashes. In order to use the number, press [ CE ].


For example, to calculate the angle between vectors, use the following keystrokes:

[CE] (to make the number stop flashing) [ ÷ ] [ ( ] [ RCL ] 5 [ × ] [ RCL ] 6 [ ) ] [ = ] [ INV ] [ cos ]


Code:


Step

Key Code

Key


Step

Key Code

Key

00

61

RCL


16

36

P→ R

01

01

1


17

31

x<>y

02

31

x<>y


18

51

STO

03

61

RCL


19

06

6

04

02

2


20

61

RCL

05

21

INV


21

01

1

06

36

P→ R


22

55

×

07

31

x<>y


23

61

RCL

08

51

STO


24

03

3

09

05

5


25

75

+

10

61

RCL


26

61

RCL

11

03

3


27

02

2

12

31

x<>y


28

55

×

13

61

RCL


29

61

RCL

14

04

4


30

04

4

15

21

INV


31

85

=



Example:


[ R1, R2 ] = [ 19, -38 ]

[ R3, R4 ] = [ 32, 64 ]


19 STO 1

38 +/- STO 2

32 STO 3

64 STO 4

R/S


Results:


Norms:

| [ R1, R2] | = R5 = 42.485292

| [ R3, R4] | = R6 = 71.554175


Dot Product: -1284


Find out the angle between the vectors: [19, -38] and [ 32, 64]

After the program is ran:

[CE] (to make the number stop flashing) [ ÷ ] [ ( ] [ RCL ] 5 [ × ] [ RCL ] 6 [ ) ] [ = ] [ INV ] [ cos ]

Angle: 126.8699°


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.

HP Prime and TI-84 Plus CE Python: Quartiles of a Data Set

HP Prime and TI-84 Plus CE Python: Quartiles of a Data Set 25 th , 50 th , and 75 th Percentiles The following code finds five ...