Saturday, June 28, 2025

fx-991 CW: Finding the Eigenvalues of a 2 x 2 Matrix

fx-991 CW: Finding the Eigenvalues of a 2 x 2 Matrix



Finding the Eigenvalues of a 2 x 2 Matrix


To find the eigenvalues of a matrix M, the characteristic polynomial must be solved in terms of λ:


det( M – λ * I) = 0


where:

M = a square matrix of dimension n x n

I = an identity matrix of size n x n.


The identity matrix is a square matrix in which all elements have a value 0 except the diagonal elements, which have the value 1.


A 2 x 2 identity matrix: [ [ 1, 0 ] [ 0, 1 ] ]

A 3 x 3 identity matrix: [ [ 1, 0, 0 ] [ 0, 1, 0 ] [ 0, 0, 1 ] ]


For a 2 x 2 matrix:


M = [ [ a, b ] [ c , d ] ]


The characteristic polynomial used to find the eigenvalues are:


det( M – λ * I) = 0

det( [ [ a, b ] [ c , d ] ] - λ * [ [ 1, 0 ] [ 0, 1 ] ] ) = 0

det( [ [ a, b ] [ c , d ] ] - [ [ λ, 0 ] [ 0, λ ] ] ) = 0

det( [ [ a - λ, b ] [ c , d - λ ] ] ) = 0

(a – λ) * (d – λ) – b * c = 0

λ^2 – (a + d) * λ + (a * d – b * c) = 0


Note:

trace(M) = a + d

det(M) = a * d – b * c


The characteristic equation to be solved is:


λ^2 – (a + d) * λ + (a * d – b * c) = 0

λ^2 – trace(M) * λ + det(M) = 0



Casio fx-991CW Algorithm


The algorithm will involve two apps: Matrix and Equation. Here is a way of finding the eigenvalues of a 2 x 2 matrices using only the fx-991 CW calculator without the need for writing anything down.


Note: The variables I use in the procedure is just for illustrative purposes. You can use any variables you want to designate the corner elements, the trace, and the determinant. The point is to be organized.


Variables used in this procedure:

A = upper-left element

B = lower-right element

C = trace = A + B

D = determinant


Settings: It is assumed that the MathI/MathO Input/Output mode and a+bi is selected for Complex result.


The screen shots are generated using the ClassPad Math (classpad.net) emulator for the fx-991CW and illustrates finding the eigenvalues of the matrix:


MatA = [ [ 4, 2 ] [ 5, 4 ] ]


Matrix App


Step 1: Press the [ HOME ] key, select the Matrix app.


Step 2: Use the TOOLS key to define a Matrix of dimension 2 x 2.


Step 3: Enter the matrix’s elements. Register each element is registered by using [ OK ] or [ EXE ]. Be careful not to press [ EXE ] or [ OK ] without entering a value first, as we need to keep the matrix editing screen up.


Step 4: Go to element (1,1) (upper-left hand corner), press the [ VARIABLE] key, go to variable A, press [ OK ], and select Store. Then go to element (2,2) (lower-right hand corner), press the [ VARIABLE] key, go to variable B, press [ OK ], and select Store.**


Step 5: Without entering or editing an element, press either [ EXE ] or [ OK ] to leave the matrix editor. When the message “Press [TOOLS] to define Matrix.” appears, we are in the calculation mode of the Matrix app.


Note: If you leave the matrix edit mode before storing the corner elements, you can go back into matrix edit mode by pressing [ TOOLS ], selecting your matrix, and then selecting Edit. You can check to see if corner values are stored by pressing [ VARIABLE ].





Step 6: Press [ SHIFT ] [ 4 ] (A) + [ SHIFT ] [ 7 ] ( B ) [ EXE ]. This calculates the matrix’s trace. Then press [ VARIABLE ], choose C, press [ OK ], choose Store.


Step 7: Press [ CATALOG ], select the Matrix sub-menu, then the Matrix Calc sub-menu, and select Determinant. Then use the catalog to grab the matrix and press [ EXE ] to calculate the matrix. Use the variable list to store the value in D (similar procedure in Step 6).





When transferring between apps, the values stored in the memory registers A-F, x, y, and z are retained, even when the fx-991CW is turned off.


Equations App


Step 8: Press [ HOME ] and select the Equation app and press [ OK ]. Select Polynomial, ax²+bx+c (2nd order polynomial, quadratic equation).


Step 9: Enter the following coefficients: 1 x² – C x + D (note the minus sign on C).


Step 10: Press [ OK ]. The first eigenvalue is displayed. Press the down arrow ([↓]) to get the other eigenvalue. 

 An optional step is to use the [ VARIABLE ] key to store the results (like in E or F, for example). 

 Another optional step is to press [ FORMAT ], select Decimal to see the decimal approximation.





The results are:


C = trace = 8

D = determinant = 6

Eigenvalues:

λ1 = 4 + √10

λ2 = 4 - √10



Other Examples



Find the eigenvalues of Mat B = [ [ -8, 1 ] [ 16, 7 ] ]


Results:

C = trace = -1

D = determinant = -72

Eigenvalues:

λ1 = 8

λ2 = -9





Find the eigenvalues of Mat C = [ [ -5, -7 ] [ 3, - 2] ]


Results:

C = trace = -7

D = determinant = 31

Eigenvalues:

λ1 = (-7 + 5 * √3 * i) / 2

λ2 = (-7 - 5 * √3 * i) / 2




I hope you find this useful and beneficial. 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, June 21, 2025

Numworks vs TI-83 Premium/TI-84 Plus CE Python: Drawing and Equals Sign Using Turtle

Numworks vs TI-83 Premium/TI-84 Plus CE Python: Drawing and Equals Sign Using Turtle


Even though many graphing calculators now have Python, and many of them have the same-named modules, the modules and commands can differ between calculators. It is very important to consult the calculator’s manual and the calculator’s help facilities to see what the particular calculator can and can not do.


The goal of halfequ.py is to draw an equals sign using the Turtle module.




Numworks: halfequ.py


from math import *
from turtle import *

# drawing equals sign
# Numworks

def hequ():
  for i in range(10):
    setheading(0)
    forward(120)
    right(90)
    forward(1)
    right(90)
    forward(120)
    left(90)
    forward(1)

# draw equals sign

speed(7)
penup()
goto(-60,-20)
pendown()
hequ()

penup()
goto(-60,40)
pendown()
hequ()

penup()
goto(0,0)
setheading(0)


TI-84 Plus CE Python/TI-83 Premium Python Edition: HALFEQU.py


from turtle import *
t=Turtle()

def hequ():
  for i in range(10):
    t.setheading(0)
    t.forward(120)
    t.right(90)
    t.forward(1)
    t.right(90)
    t.forward(120)
    t.left(90)
    t.forward(1)

t.speed(7)
t.penup()
t.goto(-60,-20)
t.pendown()
hequ()

t.penup()
t.goto(-60,40)
t.pendown()
hequ()

t.penup()
t.home()
t.done()


Notes


* The turtle module is an add-on module for the TI-84 Plus CE/TI-83 Premium Python Edition, which requires a separate download.

* The Numworks turtle does not require named object of turtle like TI does. The TI requiring a “named” turtle may open the possibility of having more than one turtle.

* The TI’s command, t.home(), puts the turtle at point (0,0) with an orientation of 0°.

* In TI’s turtle, t.done() must be at the end of the code in order for the drawing to commence.

* In Numworks, the turtle is represented as a turtle, while the TI’s turtle is represented as an arrow.

* In Numworks, the turtle can be displayed or hidden by the showturtle() or hideturtle() command, respectively.

* Numworks’ drawing range: x = [-160, 160], y = [-111, 111].

* TI’s turtle drawing range: x = [-160, 160], y = [-120, 120].


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 14, 2025

RPN With DM32: Interest Conversions

RPN With DM32: Interest Conversions



Today’s edition of RPN will focus on the Swiss Micros DM32 and HP 32SII calculator family (32SII, 33s 35s). My plan is to expand the range of calculators used in the RPN series to include the HP 41C/DM41X, HP 42S/DM42(n), HP 11C in addition to the HP 32SII and HP 15C families.



Nominal Interest Rate (EFF/NOM) and Effective Interest Rate (EFF)


When loans, annuities, mortgage, and other time-valued financial instruments are executed, the interest rate typically given is known as the nominal interest rate (NOM), also known as the APR. In mortgages and auto loans where the payments typically take place every month (12 per year), the periodic interest rate is divided by 12 to come up with the periodic rate. The periodic rate is compounded every month.


For example, if a loan has an APR (nominal rate, NOM) of 6% and payments take place monthly, the periodic interest rate is:


6% / 12 = 0.5%


The effective interest (EFF) rate is the nominal interest rate calculated as if was compounded annually.


Paid in Arrears


Typically, payments are paid in arrears, meaning payments are made after the service or the use of associated goods were provided. An example is the mortgage payment for the month of June is paid in the beginning of July.


The effective rate for payments paid in arrears is:


EFF% = (1 + NOM% / PY) ^ PY - 1


EFF%: effective interest rate

NOM%: nominal interest rate, APR

PY: payments per year


The effective rate for a APR of 6%, compounded monthly, paid in arrears is:


EFF% = (1 + 6% / 12) ^ 12 – 1 = (1 + 0.06 / 12)^12 – 1 ≈ 0.06168 (6.168%)



Paid in Advance


Sometimes, payments are paid in advance, where payments are made before the service or use of associated goods are provided. For example, the mortgage payment for the month of June is paid at the beginning of June or the end of May. The mortgage is paid in advance.


The effective rate for payments paid in arrears is:


EFF% = (1 - NOM% / PY) ^ (-PY) - 1


EFF%: effective interest rate

NOM%: nominal interest rate, APR

PY: payments per year


The effective rate for a APR of 6%, compounded monthly, paid in advance is:


EFF% = (1 - 6% / 12) ^ (-12) – 1 = (1 - 0.06 / 12)^(-12) – 1 ≈ 0.06200 (6.2%)



Conversion Formulas


The conversion formulas are (see source):

Payments in Arrears


EFF% = (1 + NOM% / PY) ^ PY – 1

NOM% = PY * ((1 + EFF%) ^ (1 / PY) – 1)


Payments in Advance


EFF% = (1 – NOM% / PY) ^ (-PY) – 1

NOM% = PY * (1 – (1 + EFF%)^(-PY))



DM32: Two Ways to Solve


There are two approaches to converting interest rates: directly through a program and using the solver.


Direct Programs


LBL A: NOM to EFF, Payments in Arrears


LBL A
STO Z
÷
1
x<>y
%
+
RCL Z
y^x
1
-
2
10^x
×
RTN


Syntax:

Y: NOM

X: PY

XEQ A


(Y: 5, X: 12, XEQ A: 5.11619)



LBL B: NOM to EFF, Payment in Advance


LBL B
STO Z
÷
1
x<>y
%
-
RCL Z
+/-
y^x
1
-
2
10^x
×
RTN


Syntax:

Y: NOM

X: PY

XEQ B


(Y: 5, X: 12, XEQ B: 5.13809)



LBL C: EFF to NOM, Payments in Arrears


LBL C
STO Z
1/x
x<>y
1
x<>y
%
+
x<>y
y^x
1
-
RCL× Z
2
10^x
×
RTN


Syntax:

Y: EFF

X: PY

XEQ C


(Y: 5, X: 12, XEQ C: 4.88895)



LBL D: EFF to NOM, Payment in Advance


LBL D
STO Z
1/x
+/-
x<>y
1
x<>y
%
+
x<>y
y^x
1
x<>y
-
RCL× Z
2
10^x
×
RTN


Syntax:

Y: EFF

X: PY

XEQ D


(Y: 5, X: 12, XEQ D: 4.86911)



Using The Solver


The DM32, and by extension, the HP 32SII, HP 33s, and HP 35s, has a solver that can solve for any variable. The solver uses a program in the format:


LBL α

INPUT (var)

INPUT (var)

function(var) = 0

RTN


To solve the equation (DM32, HP 32SII):


1. Press [ blue shift/right shift ] [ XEQ ] (FN=). An FN= prompt appears asking for a label.

2. Press [ blue shift/right shift ] [ 7 ] (SOLVE). You will be prompted to enter the variable to be solved.

3. The calculator prompts for values for any of the values. Press [ R/S ] to accept.

4. The solution is shown. I think the values and solutions are stored in the solutions. It is the case for the DM32, HP 32SII, and HP 32S.


Notes:

* HP 32S has the FN= and SOLVE in the SOLVE/∫ menu ([orange shift ] [ 1 ]).

* The right shift turned lavender in later HP 32SII calculators (late 1990s/early 2000s).


LBL S: Solver

LBL S
INPUT E
INPUT M
INPUT N
1
RCL M
RCL÷ N
+
RCL N
y^x
1
-
RCL- E
RTN


The equation is:

E = (1 + M/N) ^ N – 1


E = EFF%

M = NOM% (or APR%)

N = payments per year


The EFF% and NOM% must be entered in decimal. For payments in arrears, enter N as positive. For payments in advance, enter N as negative.


Example


Set function as:


FN= S

NOM to EFF, pmts in arrears


Solve E


M = 5% = 0.05

N = 12


E = 0.05116

(5.116%)

NOM to EFF, pmts in advance


Solve E


M = 5% = 0.05

N = -12


E = 0.05138

(5.138%)

EFF to NOM,

pmts in arrears


Solve M


E = 5% = 0.05

N = 12


M = 0.04889

(4.889%)

EFF to NOM,

pmts in advance


Solve M


E = 5% = 0.05

N = -12


M = 0.04869

(4.869%)


Source


J.J. Rose and E.M. Reeves VALPAC: A Discounted Cash Flow Approach To Property Valuation. (user manual) The Incorporated Society of Valuers and Auctioneers. An HP 41C Pac.


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.

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.

fx-991 CW: Finding the Eigenvalues of a 2 x 2 Matrix

fx-991 CW: Finding the Eigenvalues of a 2 x 2 Matrix Finding the Eigenvalues of a 2 x 2 Matrix To find the eigenvalues of a matr...