3
$\begingroup$

I have a question, how to obtain independent variables from a set of linear constraints. Let me illuminate this by a simple example, we have 5 variables and 3 linear constraints,

$x1+x2+2*(x3+x4)+x5=0$;

$4*(x1+x2)+3*(x3+x4)+x5=0$;

$x1+x2+x3+x4+x5=0$.

If we calculate the equations by hand, we obtain

$x1+x2=0; x3+x4=0; x5=0;$

so we have two independent variables, we can choose $x1$ and $x3$ as one possibility. My question is how to obtain independent variables by Mathematica, suppose we have more variables and constraints, so that hand calculation is impossible.

Thanks very much for your help.

$\endgroup$
4
  • $\begingroup$ Welcome to the Mathematica Stack Exchange. Could you please load your equations as Mathematica code? You can copy directly from the input cell and paste it in the Edit window. There is a { } icon there to format it. $\endgroup$
    – Syed
    Jun 13 at 14:22
  • $\begingroup$ Look at the documentation for Solve. $\endgroup$
    – N.J.Evans
    Jun 13 at 14:29
  • $\begingroup$ Thanks for your reply, I do not have a Mathematica code. I just do not know how to solve this problem by Mathematica. $\endgroup$ Jun 13 at 14:29
  • $\begingroup$ Yes, if I try {Solve[ x1 + x2 + 2*(x3 + x4) + x5 == 0 && 4*(x1 + x2) + 3*(x3 + x4) + 2*x5 == 0 && 4*(x1 + x2) + (x3 + x4) + x5 == 0, {x2, x4, x5}]} by Mathematica, it give solutions for x2, x4 and x5, if we consider x1 and x3 as independent variables. However, my question is how do I know x1 and x3 are independent variables? Could you please show me more hints? $\endgroup$ Jun 13 at 14:35

2 Answers 2

8
$\begingroup$

First one can set up and solve the system.

linpolys = {x1 + x2 + 2*(x3 + x4) + x5, 
   4*(x1 + x2) + 3*(x3 + x4) + x5, x1 + x2 + x3 + x4 + x5};
solns = Solve[linpolys == 0]

(* Out[83]= {{x2 -> -x1, x4 -> -x3, x5 -> 0}} *)

Now find which variables were used as parameters to describe the solution set.

indepvars = Variables[Variables[linpolys] /. solns]

(* Out[84]= {x1, x3} *)
$\endgroup$
0
4
$\begingroup$
Clear["Global`*"]

eqns = x1 + x2 + 2*(x3 + x4) + x5 == 0 && 
   4*(x1 + x2) + 3*(x3 + x4) + 2*x5 == 0 && 
   4*(x1 + x2) + (x3 + x4) + x5 == 0;

vars = Variables[Level[eqns, {-1}]];

solVar = Subsets[vars, {3}];

{#, sol = Solve[eqns, #], 
     If[sol === {}, "-", Complement[vars, #]]} & /@ solVar //
  Prepend[#, {"  Solve\nvariables", "Solutions", 
     "Independent\n variables"}] & //
 Grid[#, Frame -> All, Alignment -> {Center, Center}] &

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.