pure math but solvable by programig,... first use the Gilles-Philippe Paillé comment and separate variables:
(k1*x + k2*y + k4)^2 = k7
(k2*y + k3*z + k5)^2 = k8
(k3*z + k1*x + k6)^2 = k9
-------------------------
k1*x + k2*y + k4 = sqrt(k7)
k2*y + k3*z + k5 = sqrt(k8)
k3*z + k1*x + k6 = sqrt(k9)
-------------------------
k1*x + k2*y = sqrt(k7) - k4
k2*y + k3*z = sqrt(k8) - k5
k3*z + k1*x = sqrt(k9) - k6
-------------------------
k1*x + k2*y + 0*z = sqrt(k7) - k4
0*x + k2*y + k3*z = sqrt(k8) - k5
k1*x + 0*y + k3*z = sqrt(k9) - k6
-------------------------
Now you can rewrite to matrix form
| k1 k2 0 |
A = | 0 k2 k3 |
| k1 0 k3 |
| x |
B = | y |
| z |
| sqrt(k7) - k4 |
C = | sqrt(k8) - k5 |
| sqrt(k9) - k6 |
A * B = C
Inverse(A) * A * B = Inverse(A) * C
B = Inverse(A) * C
So its simple Inverse of 3x3 matrix. If you expand it to 4x4 by zeor padding and adding 1 to diagonal You can use 4x4 matrix inverse like this:
Just look for matrix_inv
in the C++ code example. You can find also the multiplication of matrix and vector there too matrix_mul_vector
...
The code would in C++ look like this:
double A[16]=
{
k1, 0,k1, 0,
k2,k2, 0, 0,
0,k3,k3, 0,
0, 0, 0, 1
};
double B[4],C[4]=
{
sqrt(k7) - k4,
sqrt(k8) - k5,
sqrt(k9) - k6
};
matrix_inv(A,A);
matrix_mul(B,A,C);
now B
should hold your resulting x,y,z
values if your equation has solution. What is left is just to add sign combinations as the sqrt
of the system loss it ... In case all constants and variables are non negative you can forget about this and use the result directly without trying the 8 combinations ...
If I see it right the combinations are done like this
double C[4]=
{
(+/-)sqrt(k7) - k4,
(+/-)sqrt(k8) - k5,
(+/-)sqrt(k9) - k6
};
so for each of the 8 C
combinations compute the result ... The combinations itself can be done by a for cycle using 3 lowest bits of iterator variable to decide the sign like:
matrix_inv(A,A);
for (int i=0;i<8;i++)
{
if ((i&1)==0) C[0]=+sqrt(k7)-k4; else C[0]=-sqrt(k7)-k4;
if ((i&2)==0) C[1]=+sqrt(k8)-k5; else C[1]=-sqrt(k8)-k5;
if ((i&4)==0) C[2]=+sqrt(k9)-k6; else C[2]=-sqrt(k9)-k6;
matrix_mul(B,A,C);
// here B holds the i-th solution
}
In case of complex domain just change the double
with a complex data-type...