Post Reply 
(71B) 3x3 Matrices: Determinant/Inverse/3x3 Systems
06-29-2016, 12:34 PM
Post: #1
(71B) 3x3 Matrices: Determinant/Inverse/3x3 Systems
HP 71B 3x3 Matrices
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

Code:

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 ]]
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)