# Solving a system with 4 variables and 4 equations

I am trying to solve a linear system of equations with Mathematica. My variables are x1, x2, x3, x4. I use the code shown below, but it gives error saying that:

Equations may not give solutions for all "solve" variables.

Even when I used LinearSolve, I got the same error.

Solve[{(x1 - ((-m3* n2 + m2 * z3 - 0.5*m2*z3)* x2 + (0.5 *n2* z3)*
x3 + (0.5 *m2 * z3)*x4)/((-1.5) n2* z3)) == (2/
1.5)   ,  (x2 -  ((m3* n2 - 0.5*m3 *n2 - m2 * z3)*
x1 + (0.5* m3* n2)* x3 + (0.5* m2* m3)*
x4)/((-1.5) (m2* m3)) ) == (-m3* n2 + m2* z3 )/((-1.5) m2*
m3)  ,    (x3 - ((-n2*  z1 + .5*n2 * z1)*
x1 + (.5* m2 * z1 - m2 * z1)*x2 + (m1 *n2  - 0.5* m2* z1)*
x4 )/((1.5) n2 z1) ) ==  (2/1.5 )  ,   (
x4 - ((-m1 *n2 + 0.5*m1 *n2 )*x1 + (-0.5 *m1* m2) *
x2 + (-.5* m1* n2 + m2 *z1)*x3)/((1.5) m1* m2) ) == (
m1* n2 - m2* z1)/((1.5)* m1* m2)} , {x1, x2, x3, x4}]


• Apparently, your equations have a certain redundancy such that there is a 1-paremeterfamily of solutions (parameterized by x1). Sep 7, 2018 at 22:46
• You can select which of your variables is the parameter: FullSimplify[ Solve[eqns//Rationalize, #, Reals] & /@ Subsets[{x1, x2, x3, x4}, {3}]] Sep 7, 2018 at 23:56
• Use Reduce instead of Solve. Sep 8, 2018 at 4:42
• In this case, you probably want to use 1/2 rather than 0.5. This uses exact numbers rather than approximate numbers. Sep 8, 2018 at 8:00
• @BobHanlon , I still get the same problem.
– mah
Sep 10, 2018 at 20:16

Extended comment.

eq = Rationalize@{(x1 - ((-m3*n2 + m2*z3 - 0.5*m2*z3)*x2 + (0.5*n2*z3)*
x3 + (0.5*m2*z3)*x4)/((-1.5) n2*z3)) == (2/
1.5), (x2 - ((m3*n2 - 0.5*m3*n2 - m2*z3)*x1 + (0.5*m3*n2)*
x3 + (0.5*m2*m3)*x4)/((-1.5) (m2*m3))) == (-m3*n2 +
m2*z3)/((-1.5) m2*
m3), (x3 - ((-n2*z1 + .5*n2*z1)*x1 + (.5*m2*z1 - m2*z1)*
x2 + (m1*n2 - 0.5*m2*z1)*x4)/((1.5) n2 z1)) == (2/
1.5), (x4 - ((-m1*n2 + 0.5*m1*n2)*x1 + (-0.5*m1*m2)*
x2 + (-.5*m1*n2 + m2*z1)*x3)/((1.5) m1*m2)) == (m1*n2 -
m2*z1)/((1.5)*m1*m2)};
sol = Solve[eq, {x1, x2, x3, x4}][];


The generic solution looks like this:

{x1, x2, x3, x4} /. sol


{x1, -(z3/m3) + (x1 z3)/ m3, -((m1 x1 (m3 n2 + m2 z3))/(m3 (m1 n2 + m2 z1))) - (-2 m1 m3 n2 - m2 m3 z1 - m1 m2 z3)/(m3 (m1 n2 + m2 z1)), (z1 (m3 n2 + m2 z3))/( m3 (m1 n2 + m2 z1)) - (x1 z1 (m3 n2 + m2 z3))/(m3 (m1 n2 + m2 z1))}

Let's check that these really are solutions by substituting the solutions rules sol into the equation eq:

eq /. sol // Simplify


{True, True, True, True}

So the equations do not specify a single solution. Because there are 4 equations and four variables, that means that the equations are somewhat redundant. Usually, one would expect to get only finitely many (or countably many) solution. This is not the case here: We have a continuum of solutions. Because that is somewhat unexpected (and because this often causes problems), Solve warns us. That's all. The message is a warning, not an error.

• I got it. Your explanation was great.
– mah
Sep 10, 2018 at 20:44
• If you like, you can mark it as "accepted", signaling that your question is answered. Sep 10, 2018 at 20:53