Showing posts with label 3 x 3 matrices. Show all posts
Showing posts with label 3 x 3 matrices. Show all posts

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.



Thursday, June 30, 2016

Fun With the HP 71B III

Fun With the HP 71B III


3x3 Matrices: Determinant, Inverse, 3x3 Linear Systems
EWS 6/29/2016

The program MATX3 calculates:

1. The determinant and (if possible), the inverse of a 3x3 matrix M.
2. The solution to a 3x3 linear system: Mq=D. The determinant of M will also be displayed.

If det(M) = 0, then the matrix is singular and execution stops.

The matrix M is broken into three columns (3x1 arrays): [ M ] = [ A | B | C ].

Hence M = [[ A1 B1 C1 ] [ A2 B2 C2 ] [ A3 B3 C3 ]]

Other variables used:
E = det(M)
I = M^-1. Unlike M, I will be a 3 x 3 array.
R, K, S, H: other variables used

Program MATX3 (767 bytes)
10 DESTROY A,B,I,C,R,K,S,H,D,Q
11 DISP “1. DET/INV  2. 3x3” @ WAIT 2
12 INPUT “1. D/I 2. SYS:”; H
13 DIM A(3),B(3),C(3),I(3,3),D(3)
14 OPTION BASE 1
20 FOR K=1 TO 3
21 DISP “ROW “;K @ WAIT 1
22 INPUT “A:”; A(K)
24 INPUT “B:”; B(K)
26 INPUT “C:”; C(K)
28 IF H=2 THEN INPUT “D:”; D(K)
30 NEXT K
40 DEF FND(X,Y,Z,T)=X*T-Y*Z
42 E=A(1)*FND(B(2),C(2),B(3),C(3))
44 E=E-B(1)*FND(A(2),C(2),A(3),C(3))
46 E=E+C(1)*FND(A(2),B(2),A(3),B(3))
50 DISP “DET:”; E
52 IF E=0 THEN STOP
60 I(1,1)=FND(B(2),B(3),C(2),C(3))/E
62 I(1,2)=-FND(B(1),B(3),C(1),C(3))/E
64 I(1,3)=FND(B(1),B(2),C(1),C(2))/E
66 I(2,1)=-FND(A(2),A(3),C(2),C(3))/E
68 I(2,2)=FND(A(1),A(3),C(1),C(3))/E
70 I(2,3)=-FND(A(1),A(2),C(1),C(2))/E
72 I(3,1)=FND(A(2),A(3),B(2),B(3))/E
74 I(3,2)=-FND(A(1),A(3),B(1),B(3))/E
76 I(3,3)=FND(A(1),A(2),B(1),B(2))/E
78 IF H=2 THEN 100
80 FOR R=1 TO 3
82 FOR S=1 TO 3
84 DISP “I(“; R; “,”; S; “):”; I(R,S)
86 PAUSE
88 NEXT S
90 NEXT R
92 STOP
100 DIM Q(3)
102 FOR K=1 TO 3
104 Q(K)= I(K,1)*D(1) + I(K,2)*D(2) + I(K,3)*D(3)
106 DISP “Q”; K; “:”; Q(K) @ PAUSE
108 NEXT K

Example:

M = [[ 1, 2, -8 ] [ 0, -2, 9.5 ] [ 3.2, 2.7, -1 ]]
D = [[ 0.5 ] [ 1.5 ] [ 2.5 ]]

DET = -14.05
I ≈ [[ 1.6833, 1.3950, -0.2135 ] [ -2.1637, -1.7509, 0.6762 ] [ -0.4555, -0.2633, 0.1423 ]]

Solutions:
Q ≈ [[ 2.4004 ] [ -2.0178 ] [ -0.2669 ]]

Days From January 1, Days Between Dates
HP 71B – Day Counts

Number of Days from January 1

D = Day
M = Month
L = Leap Year indicator (1 if the year is a leap year, 0 if it is not)

Program DAYJAN1 (183 bytes)
10 DESTROY D,M,L,N
12 INPUT “MONTH:”; M
14 INPUT “DAY:”; D
16 INPUT “LEAP? (Y=1,N=0):”; L
20 IF M>2 THEN 28
21 REM M<=2
22 N=IP(30.6*(M+13))+D-429
24 GOTO 32
27 REM M>2
28 N=IP(30.6*(M+1))+D+L-64
32 DISP “# DAYS:”; N

Test 1: January 1 to May 29, non-leap year (L=0). Result: 148
Test 2: January 1 to May 29, leap year (L=1). Result: 149

Days between Dates

M, D, Y: Month, Day, four-digit year

Program DDAYS (299 bytes)
10 DESTROY M1, M2, D1, D2, Y1, Y2, F1, F2
11 DESTROY F,M,D,Y,N,X,Z
12 INPUT “1: M,D,Y:”; M1, D1, Y1
13 INPUT “2: M,D,Y:”; M2, D2, Y2
15 M=M1 @ D=D1 @ Y=Y1
17 GOSUB 40
19 F1=F
21 M=M2 @ D=D2 @ Y=Y2
23 GOSUB 40
25 F2=F
27 N=F2-F1
29 DISP “# DAYS:”; N
31 STOP
40 IF M>2 THEN X=IP(.4*M+2.3) ELSE X=0
42 IF M>2 THEN Z=Y ELSE Z=Y-1
44 F=365*Y+31*(M-1)+D+IP(Z/4)-X
46 RETURN

Test 1: January 2, 2015 to March 17, 2016 (1,2,2015 to 3,17,2016). Result: 440
Test 2: March 14, 1977 to June 29, 2016 (3,14,1977 to 6,29,2016). Result: 14352

Great Circle Distance

N: Longitude
E: Latitude

Separate Degrees (H), Minutes (M), and Seconds (S) during input
Program GRCIC (367 bytes)
10 DESTROY D,M,H,S
11 DESTROY N1,N2,E1,E2,G
12 DEGREES
14 DISP “N: LATITUDE” @ WAIT 1
16 DISP “E: LONGITUDE” @ WAIT 1
20 INPUT “N1: D,M,S:”; H,M,S
21 GOSUB 50
22 N1=D
25 INPUT “E1: D,M,S:”; H,M,S
26 GOSUB 50
27 E1=D
30 INPUT “N2: D,M,S:”; H,M,S
31 GOSUB 50
32 N2=D
35 INPUT “E2: D,M,S:”; H,M,S
36 GOSUB 50
37 E2=D
40 REM CALCULATION
41 G=SIN(N1)*SIN(N2)+COS(N1)*COS(N2)*COS(E1-E2)
42 G=ACOS(G)*3959*PI/180
44 DISP “DIST: “; G; “ MI”
46 STOP
50 D=SGN(H)*(ABS(H)+M/60+S/3600)
52 RETURN

Test:
Los Angeles, N = 34°13’0” and E = -118°15’0”
San Francisco, N = 37°47’0” and E = -112°25’0”
Distance ≈ 408.5961 mi

Euclid Division – Finding the GCD

Finds the GCD (greatest common divisor) between integers M and N.  The program displays a “calculating” screen while the calculation is in process.

Program EUCLID (143 bytes)
10 DESTROY M,N,A,B,C
15 INPUT “M,N:”; M,N
20 IF M>N THEN A=M  @ B=N
22 IF M<N THEN A=N @ B=M
30 C= A – IP(A/B)*B
35 DISP C;B;A   // this is the “busy” indicator
40 IF C=0 THEN 50
45 A=B @ B=C @ GOTO 30
50 DISP “GCD:”; B

Test 1:  M=144, N=14;  Result: 2
Test 2:  N=14, M=144;  Result: 2

Fractions:  Addition and Multiplication

Adds or multiplies two fractions W/X and Y/Z.  Gives the result in the simplest form.  Proper or improper fractions only.

Separate each part with a comma (W,X,Y,Z) as prompted.

Program FRAC (380 bytes)
10 DESTROY W,X,Y,Z,N,D,H,A,B,C
20 INPUT “1. + 2. *:”,H
24 ON H GOTO 41,51
41 REM ADD
42 INPUT “W/X+Y/Z:”; W,X,Y,Z
44 N=W*Z+X*Y @ D=X*Y
46 GOSUB 61
48 DISP “=”; N; “/”; D @ STOP
51 REM MULT
52 INPUT “W/X*Y/Z:”; W
54 N=W*Y @ D=X*Z
56 GOSUB 61
58 DISP “=”; N; “/”; D @ STOP
61 REM SIMPLIFY
62 IF N>D THEN A=N @ B=D
64 IF D>N THEN A=D @ B=N
66 IF D=N THEN N=1 @ D=1 @ RETURN
68 C= A – IP(A/B)*B
69 DISP C;B;A
70 IF C=0 THEN 74
72 A=B @ B=C @ GOTO 68
74 N=N/B @ D=D/B @ RETURN

Test 1:  4/7 + 3/13;   Input:  4,7,3,13.  Result:  73/91
Test 2: 4/7 * 3/13; Input: 4,7,3,13.  Result:  12/91

Statistics: Regression

The program CURVEFIT fits data to one of five regression models:

1.  Linear Regression:  y = a + bx
2.  Exponential Regression:  y = a * e^(b*x)
3.  Logarithm Regression: y = a + b * ln x
4.  Power Regression:  y = a * x^b
5.  Inverse Regression:  y = a + b/x

On the HP 71, the ln function is represented by LOG.

The program will allow different calculations with the same data set.

Program CURVEFIT (622 bytes)
10 DESTROY H,S,D,X,Y,A,B,E
12 STAT S(2) @ CLSTAT
20 REM CHOOSE REG
22 DISP “1. LIN 2. EXP 3. LOG” @ WAIT 1.5
24 DISP “4. POW 5. INV” @ WAIT 1.5
28 INPUT “CHOICE #:”; H
29 IF E=1 THEN 60
30 REM INPUT PROCESS
32 INPUT “X,Y:”; X,Y
34 ON H GOTO 36,38,40,42,44
36 ADD X,Y @ GOTO 46
38 ADD X,LOG(Y) @ GOTO 46
40 ADD LOG(X),Y @ GOTO 46
42 ADD LOG(X),LOG(Y) @ GOTO 46
44 ADD 1/X,Y @ GOTO 46
46 INPUT “DONE? (Y=1,N=0):”; D
48 IF D=0 THEN 32
60 LR 2,1,A,B
62 IF H=2 OR H=4 THEN A=EXP(A)
64 ON H GOTO 70,72,74,76,78
70 DISP A; “+”; B; “x” @ GOTO 80
72 DISP A; “*EXP(“; B; “x)” @ GOTO 80
74 DISP A; “+”; B; “*LOG(x)” @ GOTO 80
76 DISP A; “x^”; B @ GOTO 80
78 DISP A; “+”; B; “/x” @ GOTO 80
80 PAUSE
84 DISP “ANOTHER ANALYSIS?” @ WAIT 1.5
86 INPUT “Y=1,N=0:”; E
88 IF E=1 THEN 20
90 DISP “DONE”


 Have fun!  See you in the second half of 2016!  

Eddie

This blog is property of Edward Shore, 2016

Wednesday, December 5, 2012

Numeric CAS - Part 11: Eigenvalues of 3 x 3 Matrices

Eigenvalues of 3 x 3 Matrices

Many graphing calculators that do not have CAS (computer algebraic systems) do not have eigenvalues and eigenvector functions.

The programs for the Casio Prizm and TI-84+ gives eigenvalues of 3 x 3 matrices.

For the HP 39gii has the functions EIGENVAL for eigenvalues.

Example:
A = [[2, -2, 3][-1, 0, 1][6, -3, 3]]

Eigenvalues:
≈ 0.2465, -1.8447, 6.5982


Casio Prizm:

EIGEN3
Eigenvalues of a 3 × 3 Matrix
Circa 2011 - 244 bytes

a+bi
"3 × 3 Matrix"? → Mat A
Mat A[1,1] + Mat A[2,2] + Mat A[3,3] → T
(Mat A)² → Mat B
Mat B[1,1] + Mat B[2,2] + Mat B[3,3] → U
Solve(-X^3 + X^2 × T + X × 1/2 × (U-T^2) + Det Mat A,0)→ R ◢
-R^2 + R × T - T^2 ÷ 2 + U ÷ 2 → A
-R + T → B
1/2 × (B - √(4A + B^2)) → E ◢
1/2 × (B + √(4A + B^2)) → F ◢
"STORED IN R, E, F"


TI-84+:

EIGEN3
Eigenvalues of a 3 × 3 matrix - 193 bytes
12/3/12

a+bi
Input "3 X 3 MATRIX:", [A]
[A](1,1) + [A](2,2) + [A](3,3) → T
[A]² → [B]
[B](1,1) + [B](2,2) + [B](3,3) → U
solve(-X³ + X² T + .5X(U-T²) + det([A]), X, 0) → R
Pause R
-R² + RT - T²/2 + U/2 → A
-R + T → B
.5(B - √(4A+B²)) → E
.5(B + √(4A+B²)) → F
Pause E
Pause F




This blog is property of Edward Shore. 2012

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 ...