I'm trying to solve 4 simultaneous linear equations because the result will be used in some software I'm creating.
The equations take the following form:
$ Aw + Bx + Cy - Bz = P $
$ -Bw + Ax + By + Cz = 0 $
$ Cw - Bx + Dy + Bz = 0 $
$ Bw + Cx - By + Dz = 0 $
The values of A, B, C, D and P can be considered constant, as they're determined by known program variables (which change at runtime), whereas w, x, y and z are determined by these equations.
Because it's for a program I'm writing, I can let the computer do some of the heavy lifting, so it's not necessary for me to express w,x,y and z all in terms of only constants. That is, I'm really trying to find
z = constant (expressed in A,B,C,D & P)
y = F(z)
x = F(y,z)
w = F(x,y,z)
I made an attempt and found a solution which I will provide below, but in the larger context of the program I'm writing it isn't behaving as I expected and my reason for posting here is to determine if that's because of a problem with my math or if the problem lies elsewhere in my code.
My solution:
(Some grouping first because this took pages and as explained above, I don't really need to fully solve it):
$ E = A^2 - B^2 $
$ F = B^2 + C^2 $
$ G = PBF $
$ H = B^2 F - ACF + CDE -B^2 E $
$ I = BCE + BDE + BCF + ABF $
$ J = (D + C)(AC + B^2 ) - (A + C)(C^2 + B^2) $
$ K = (A + C)(BC + BD) $
Solving for z, y, x & w:
$ z = \frac{GK }{IJ - HK} $
$ y = \frac{PBF + (B^2 F - ACF + CDE - B^2 E) z}{BCE + BDE + BCF + ABF} $
$ x = \frac{-Dz - Cz}{A + C} $
$ w = \frac{Ax + By + Cz}{B} $
Any insights would be greatly appreciated because short of attempting to solve the whole thing instead on the off-chance made a mistake I'm not really sure what else to do.
In matrix form, the system of equations is $$ \left[ \begin{array}{cccc} A & B & C & -B \\ -B & A & B & C \\ C & - B & D & B \\ B & C & -B & D \end{array} \right] \left\{ \begin{array}{c} w \\ x \\y \\ z \end{array} \right\} = \left[ \begin{array}{c} P \\ 0 \\ 0 \\ 0 \end{array} \right] $$ There is an algebraic solution to this equation, and it can be found with the matrix inverse: $$ \left\{ \begin{array}{c} w \\ x \\y \\ z \end{array} \right\} = \left[ \begin{array}{cccc} A & B & C & -B \\ -B & A & B & C \\ C & - B & D & B \\ B & C & -B & D \end{array} \right]^{-1} \left[ \begin{array}{c} P \\ 0 \\ 0 \\ 0 \end{array} \right] $$ The inverse matrix is a bit tricky to compute, but according to Wolfram Alpha, the result is the matrix $\frac{1}{\text{det}}M$ so that the components of $M$ are
The other coefficients you need not worry about, because they are multiplied by zeros in the equation. The determinant is $$ \text{det} = A^2 (B^2 +D^2 ) + AB^2 (2C + D) - 2AC^2 D +B^2 (2C + D)^2 + C^4 $$ So in short, you can compute the unknowns by $$ \left\{ \begin{array}{c} w \\ x \\ y\\z \end{array} \right\} = \frac{1}{\text{det}} \left\{ \begin{array}{c} M_{0,0} \\ M_{0,1} \\ M_{0,2} \\ M_{0,3} \end{array} \right\} P $$