Showing posts with label determinant. Show all posts
Showing posts with label determinant. Show all posts

Saturday, June 5, 2021

7000G Retro Month - June 5 Edition

7000G Retro Month - June 5 Edition





Introduction


Welcome to the 7000G Retro Month, which features programming for the classic Casio calculators from the mid/late 1980s:  primarily fx-7000G and fx-7500G.  Since the programming language stays similar throughout the years, programs can be translated to the fx-6300G and later graphing calculators with little to no adjustments.  Non graphic programs should be ported to the fx-4000P, fx-4500P (A), fx-3650p (II), fx-50F Plus (II), and fx-5800P with little to no adjustments.  


7000G Retro Month takes place every Saturday during June 2021.


To make text easier to type, I can going to use the following text friendly symbols for the following:


->  for →


/I for ⊿


=> for ⇒


What do you think?   Unicode or simple text equivalents?  


- - - - - - -- - -- - -


Today's subject revolves around General Mathematics.  Enjoy!


- - - -- - - -- - -- -- -



Day Number of the Year


Returns the day number of a year, with January 1 being Day 1 and December 31 being day 365 (or 366 on leap years).  For LEAP? enter 0 for non leap years or 1 for leap years.   


"MONTH"? -> M

"DAY"? -> D

"LEAP"? -> L

M≤2 => D+Int(30.6M+368.8)-399 -> N

M>2 => D+Int(30.6M+1.6)-34+L -> N


Arithmetic-Geometric Mean


The arithmetic-geometric mean of two positive numbers x and y is a convergence of repeated means:


Arithmetic:  a = (x + y)/2

Geometric:  g = √(x y) 


Tolerance:  decimal to determine desired accuracy.  For example, to eight decimal places, set tolerance to 1E-8.  


"AGM"

"A0"? -> X

"G0"? -> Y

"TOL"? -> T

Lbl 1

(X+Y)÷2 -> A

√(XY) -> G

A -> X : G -> Y

Abs (A-G) ≥ T => Goto 1

A /I

G


The final A and G are displayed to show the convergence.  


Now for two classics.


Determinant of a 3 x 3 Matrix


Here the program makes use of the square brackets and indirect storage.  Yes, indirect storage and recall are possible with the fx-7000G and fx-7500G.  Of course, this program is not necessary in later graphing calculators.


A[0] = A

A[1] = B

A[2] = C

A[3] = D

A[4] = E

A[5] = F

A[6] = G

A[7] = H

A[8] = I


Elements are entered left to right, completing row by row.


The determinant is stored in the variable T.


The Isz command is used to increment K by 1.  Since K starts at 0 and K increases by 1 before comparing it, the next command is never going to be skipped.


"3 X 3 DET"

0 -> K

Lbl 1

? -> A[K]

Isz K

K < 9 => Goto 1

A(EI-FH)-B(DI-FG)+C(DH-EG) -> T


Quadratic Formula


I would consider this the "Hello World" of mathematics programs.   


Ax^2 + Bx + C = 0


Let D be the discriminant:  D = B^2 - 4AC.   D is displayed where you can determine the characteristics of the roots:


D ≥ 0:  roots are real, stored in X and Y

D < 0:  roots are complex, that take the form of X + Yi, X - Yi


"A"? -> A

"B"? -> B

"C"? -> C

B^2-4AC -> D /I

D<0 => Goto 1

(-B+√D)÷(2A) -> X

(-B-√D)÷(2A) -> Y

Goto 2

Lbl 1

-B÷(2A) -> X

√ Abs D ÷(2A) -> Y

Lbl 2

X /I Y


Eddie


All original content copyright, © 2011-2021.  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, November 21, 2020

Numworks: 3 x 3 Matrices

 Numworks:   3 x 3 Matrices


The script invthree.py calculates the inverse and determinant of a 3 x 3 matrix.  


Matrices:


[[ a1,  a2,  a3 ]

[ b1, b2, b3 ]

[ c1, c2, c3 ]]



Numworks script invthree.py:

(701 bytes)


from math import *


# 2020-11-12 EWS

print("3x3 Matrix Inverse")

print("[[a1,a2,a3]")

print("[b1,b2,b3]")

print("[c1,c2,c3]]")

a1=float(input('a1: '))

a2=float(input('a2: '))

a3=float(input('a3: '))

b1=float(input('b1: '))

b2=float(input('b2: '))

b3=float(input('b3: '))

c1=float(input('c1: '))

c2=float(input('c2: '))

c3=float(input('c3: '))

# determinant

d=a1*(b2*c3-b3*c2)-a2*(b1*c3-b3*c1)+a3*(b1*c2-b2*c1)

# inverse

d1=(b2*c3-c2*b3)/d

d2=-(a2*c3-c2*a3)/d

d3=(a2*b3-a3*b2)/d

e1=-(b1*c3-c1*b3)/d

e2=(a1*c3-c1*a3)/d

e3=-(a1*b3-a3*b1)/d

f1=(b1*c2-b2*c1)/d

f2=-(a1*c2-a2*c1)/d

f3=(a1*b2-a2*b1)/d

print("det=")

print(d)

print("inv=")

print([d1,d2,d3])

print([e1,e2,e3])

print([f1,f2,f3])


Numworks page:  https://workshop.numworks.com/python/ews31415/invthree


Example:


[[ -5.4, 3.3, -1.7 ], [ 0.6, 8.3, 5.3 ] [ 5.5, 5.4, 1.9 ]] 


returns 


[ -0.05493...,  -0.06604..., 0.13508... ]

[ 0.11974... ,  -0.00389..., 0.11798... ]

[ -0.18130..., 0.20224..., -0.20006... ]


Source:


wikiHow Staff "How to Find the Inverse of a 3x3 Matrix"  WikiHow.   Last Updated November 5, 2020.  https://www.wikihow.com/Find-the-Inverse-of-a-3x3-Matrix  Retrieved November 12, 2020.


Eddie


All original content copyright, © 2011-2020.  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, October 16, 2016

TI-84 Plus CE: Possible Matrix Bug? (Update 11/6/2016)

TI-84 Plus CE: Possible Matrix Bug?

Calculator:  TI-84 Plus CE
OS Version:  5.1.5.0019  (2016)

While creating a program to determine the radius of “as-built” circular alignments, I ran into a possible bug for the TI-84 Plus CE.  The program would call for the inverse of a matrix, and the 84 returned an error when I think it shouldn’t.  This blog entry will focus on the possible bug.

Determinant of a 3 x 3 Matrix

As we know, if the determinant of a matrix is 0, it is singular and an inverse for the matrix cannot be calculated. For a 3 x 3 matrix A, the determinant is calculated as:

|A| = S – U + V

Where:

S = A(1,1) * ( A(2,2) * A(3,3) – A(3,2) * A(2,3) )
U = A(1,2) * ( A(2,1) * A(3,3) – A(3,1) * A(2,3) )
V = A(1,3) * ( A(2,1) * A(3,2) – A(3,1) * A(2,2) )

Designation:  A(row, column)

The test program DET3TEST will calculate the determinant both was: first by the det function and the long calculation.

TI-84 Plus CE Program DET3TEST
Input [D]
det([D])→T
Disp "DET FUNCTION:"
Pause T
[D](1,1)*([D](2,2)*[D](3,3)-[D](2,3)*[D](3,2))→S
[D](1,2)*([D](2,1)*[D](3,3)-[D](3,1)*[D](2,3))→U
[D](1,3)*([D](2,1)*[D](3,2)-[D](2,2)*[D](3,1))→V
Disp "LONG WAY:",S-U+V

Test Results:

As expected most calculations will generate the same determinant using both methods.



Matrix:

4
6
3
0
1
-5
-3
-2
2

Determinant Function:  67
Long Way:  67

Matrix:

105
-262
360
435
415
360
676
330
360

Determinant Function:  -68834520
Long Way:  -68834520

Matrix:

108
76
-2
38
45
-5
-2
-5
6

Determinant Function:  10092
Long Way:  10092

Matrix:

2100
7584
2525
-1666
1724
-1826
5200
8
7543

Determinant Function:  2.796336659E10
Long Way:  2.796336659E10

Matrix:

114875.56
4173818
-127000.5
-46154
82755.275
57400
27604516
-3.12E7
304898400

Determinant Function:  1.40693245E20
Long Way:  1.40693245E20

-123456789
10.54
48275.05
112466708
48275.05
-417758
10.554
-42700.889
37200958.69

Determinant Function:  -2.19786983E20
Long Way:  -2.19786983E20


-123456789
10.54
48275.05
112466708
48275.05
-417758
10.554
-42700.889
37200958.69

Determinant Function:  -2.19786983E20
Long Way:  -2.19786983E20


So far, so good, as we expect.  Here is one matrix where it went wrong:



970057481.4792
776304082.7892
-62136.68
776304082.7892
636188513.236
-50267.64
-62136.68
-50267.64
4

Determinant Function:  0
Long Way:  3.043565238E12

Update (11/6/2016):  I recently updated the OS for the TI-84 Plus CE to version 5.2.1.0042 (2016) and tested the determinant function on this matrix again, and still got 0.  

Also, in an email from Rich Grubbs, "I have verified that the following TI calculators get the result '0' when given the same matrix: TI-nspire (3.9.0.463), TI-84 keypad in the TI-nspire (2.56MP), TI-86(1.6), TI-92+ (2.05), and TI-36X Pro (Serial K-0514B)."  Thank you Rich for information!  Much appreciated! 

I tested this matrix on Wolfram Alpha, HP Prime, and Casio Prizm and all got the latter answer (3.043565238E12).

I have not found any other matrices with mismatching answers.


This blog is property of Edward Shore, 2016.



Wednesday, July 6, 2016

TI-55 III Programs Part III: Area and Eccentricity of Ellipses, Determinant and Inverse of 2x2 Matrices, Speed of Sound/Principal Frequency

TI-55 III Programs Part III:  Area and Eccentricity of Ellipses, Determinant and Inverse of 2x2 Matrices, Speed of Sound/Principal Frequency



TI-55 III:  Area and Eccentricity of the Ellipse

Formulas:
Assume a>b, where a and b represent the lengths of semi-diameters, respectively
Area:  A = Ï€*a*b
Eccentricity:  ϵ = √(1 – (b/a)^2)

Program: 
Partitions Allowed: 1-5
STEP
CODE
KEY
COMMENT
00
71
RCL
R0 = a
01
00
0

02
65
*

03
71
RCL
R1 = b
04
01
1

05
65
*

06
91
Ï€

07
95
=

08
12
R/S
Display A
09
53
(

10
01
1

11
75
-

12
53
(

13
71
RCL

14
01
1

15
55
÷

16
71
RCL

17
00
0

18
54
)

19
18
X^2

20
54
)

21
95
=

22
13

23
12
R/S
Display ϵ

Input:  a [STO] 0, b [STO] 1, [RST] [R/S]
Result:  Area, [R/S] Eccentricity

Test:  a = 7.06, b = 3.78
Result: A ≈ 83.839055, ϵ ≈ 0.8445918

TI-55 III:  Determinant and Inverse of 2 x 2 Matrices

This program will require 4 registers. 
Input Matrix:  M = [[ R0,  R1 ] [ R2 , R3 ]]
Output Matrix:  M^-1 = [[ R3/det, -R1/det ] [ -R2/det, R0/det ]]
Where det = R0 * R3 – R1 * R2  (determinant). 

Program: 
Set 4 partitions:  [2nd] [LRN] (Part) 4
STEP
CODE
KEY
COMMENT
00
71
RCL
Calculate determinant
01
00
0

02
65
*

03
71
RCL

04
03
3

05
75
-

06
71
RCL

07
02
2

08
75
*

09
71
RCL

10
01
1

11
95
=

12
12
R/S
Display determinant
13
61
STO
Calculate inverse
14
55
÷

15
00
0

16
61
STO

17
55
÷

18
03
3

19
94
+/-

20
61
STO

21
55
÷

22
01
1

23
61
STO

24
55
÷

25
02
2

26
01
1
Display 1 to indicate “done”
27
12
R/S


Input:  Store:
M(1,1) [STO] 0
M(1,2) [STO] 1
M(2,1) [STO] 2
M(2,2) [STO] 3
Press [R/S] to calculate the determinant of M.  If M≠0, continue and press [R/S].
You will see a 1 in the display, this is used as an indicator that the program is done. 

Result Inverse Matrix:
M^-1[1,1] stored in R3
M^-1[1,2] stored in R1
M^-1[2,1] stored in R2
M^-1[2,2] stored in R0

Test: 
M =  [ [ -1.4,  3.0 ], [ 2.8, 6.4 ] ]
Determinant = -17.36
M^-1 ≈  [ [ -.3686635945, .1728110599 ], [ .1612903226, .0806451613 ] ]

TI-55 III: Speed of Sound/Fundamental Resonant Frequency

Formulas:

Speed of Sound (m/s):  v = t*0.6 + 331.4
Where t = temperature (°C)

Fundamental Resonant Frequencies in an Open Pipe:  fn = v/(2*L)
Where fn = frequency (Hz), v = speed of sound (m/s), L = length of pipe (m)

Program:
Partitions allowed:  1-5
STEP
CODE
KEY
COMMENT
00
65
*

01
93
.
Decimal point
02
06
6

03
85
+

04
03
3

05
03
3

06
01
1

07
93
.
Decimal point
08
04
4

09
95
=

10
12
R/S
Display speed of sound
11
55
÷

12
02
2

13
55
÷

14
12
R/S
Prompt for L
15
95
=

16
12
R/S
Display frequency

Speed of Sound in Dry Air: 
Input:  Enter temperature in °C [F1]
Result:  Speed of sound (m/s), press [R/S]

Fundamental Resonant Frequencies:
Store the length of the open pipe (m) then press [R/S]
Result:  Fundamental Resonant Frequency (Hz)

Test:
Open pipe of 0.45, where the temperature of the air is 39°C (102.2°F). 

Input:  39 [R/S]
Result:  354.8 m/s (speed of sound), [R/S]
394.22222 Hz (fundamental resonant frequency)

Source:  Browne Ph. D, Michael.  “Schaum’s Outlines:  Physics for Engineering and Science”  2nd Ed.  McGraw Hill: New York, 2010

 Eddie

I hope you are enjoying this series of programs for calculators from the 1980s.  The next series, I plan to stay in the 1980s when I work with the 1988 HP 42S.

This blog is property of Edward Shore.  

TI-84 Plus CE: Logistic Map

TI-84 Plus CE: Logistic Map It feels like forever since I with the TI-84 Plus CE. Introduction The program LOGISTIC plots ...