# HP Forums

Full Version: solve 3x3 system on 33s
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

Here is some code for the 33s (originally written for the 32sii) for solving a 3x3 linear system of equations.

The code uses Cramer's rule ( with determinants) and does not change the coefficients.

```Solve a 3 x 3 system of linear equations
A*X + B*Y + C*Z = D
E*X + F*Y + G*Z = H
I*X + J*Y + K*Z = L
DET =
|A B C|
|E F G|
|I J K|
=
A * (F K - G J) - E * (B K - C J) + I * (B G - C F)
D_X =
|D B C|
|H F G|
|L J K|
Same for D_Y and D_Z
x = D_X/DET,, ...
===============================================================================

S: do via determinants and column swapping
(20 steps, 43.5, E8A7):
LBL S
XEQ U; STO W; VIEW W
1; XEQ V; XEQ U; RCL/ W; STO X; 1; XEQ V
2; XEQ V; XEQ U; RCL/ W; STO Y; 2; XEQ V
3; XEQ V; XEQ U; RCL/ W; STO Z; 3; XEQ V
RTN
U: determinant of [ [a, b, c], [e, f, g], [i, j, k] ]
(33.0, A5DB)
LBL U
// DET = A * (F K - G J) - E * (B K - C J) + I * (B G - C F)
RCL F; RCL* K; RCL G; RCL* J; -; RCL* A;
RCL B; RCL* K; RCL C; RCL* J; -; RCL* E; -
RCL B; RCL* G; RCL C; RCL* F; -; RCL* I; +
RTN
V: swap column in x reg (1..3) with [d, h, l]
(24.0, 8BD5)
LBL V
STO i;
RCL D; X<> (i); STO D;
4; STO+ i;
RCL H; X<> (i); STO H;
4; STO+ i;
RCL L; X<> (i); STO L;
RTN
I: input a 3x3 system (also uses lbl J)
lbl I
1.012 STO I
LBL J
INPUT (I)
ISG I
GTO J
RTN
```

Nice work, Martin.