0
$\begingroup$

Say I have some complicated equation that contains some constant variables like this

Solve[2 a*c + 2 d*fr + 2 b*er + 2 gi  hi + 2 gr  hr == 0 &&
  2 a*d + 2 c*fr + 2 b*gr + 2  (ei  hi + er  hr) == 0 &&
  2 a*b + 2 c*er + 2 d*gr + 2  (fi  hi + fr  hr) == 0 &&
  (2 d*fi + 2 b*ei) + 2 gr *hi - 2 gi *hr == 0 &&
  (2 c*fi + 2 b*gi) + 2 er  hi - 2 ei  hr == 0 &&
  (2 c*ei + 2 d*gi) + 2 fr  hi - 2 fi  hr == 0, 
  {er, ei, fr, fi, gr, gi}, Reals]

I want to determine when for the given constants: a, b, c, d, hr, hi, a solution for er, ei, fr, fi, gr, gi exists. Using solve gives a result too long to parse manually and it doesn't say what the conditions are for existence.

A similar question was asked here but it only dealt with there being a solution matrix, aka the coefficient matrix being invertible. But in this case I just want to know when any solution exists, whether there be an infinite number or just a unique one. One idea I had was that a solution exists if the b matrix in Ax=b is in the column space of A. But I don't know how to solve that in Mathematica. Any ideas?

$\endgroup$

3 Answers 3

3
$\begingroup$
$Version

(* "14.1.0 for Mac OS X ARM (64-bit) (July 16, 2024)" *)

Clear["Global`*"]

eqns = 2 a*c + 2 d*fr + 2 b*er + 2 gi hi + 2 gr hr == 0 && 
   2 a*d + 2 c*fr + 2 b*gr + 2 (ei hi + er hr) == 0 && 
   2 a*b + 2 c*er + 2 d*gr + 2 (fi hi + fr hr) == 
    0 && (2 d*fi + 2 b*ei) + 2 gr*hi - 2 gi*hr == 
    0 && (2 c*fi + 2 b*gi) + 2 er hi - 2 ei hr == 
    0 && (2 c*ei + 2 d*gi) + 2 fr hi - 2 fi hr == 0;

vars = {er, ei, fr, fi, gr, gi};

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

(* {a, b, c, d, hi, hr} *)

sol = Assuming[vars \[Element] Reals && params \[Element] Reals,
  Solve[eqns, vars] // FullSimplify]

(* {{er -> (a (2 b c (d - hi) (d + hi) (b^2 + c^2 - d^2 - hi^2) + 
        d ((b^2 - c^2)^2 - (d^2 - hi^2)^2) hr - 
        2 b c (b^2 + c^2 - 2 hi^2) hr^2 + 2 d (d - hi) (d + hi) hr^3 + 
        2 b c hr^4 - 
        d hr^5))/(b^4 (hi^2 + hr^2) + (c^2 + d^2 - hi^2 - hr^2)^2 (hi^2 + 
         hr^2) + 2 b^2 ((d^2 - hi^2 - hr^2) (hi^2 + hr^2) + 
         c^2 (-2 d^2 + hi^2 + hr^2))), 
  ei -> -((a d hi (-(b^2 - c^2)^2 + (-d^2 + hi^2 + hr^2)^2))/(b^4 (hi^2 + 
           hr^2) + (c^2 + d^2 - hi^2 - hr^2)^2 (hi^2 + hr^2) + 
        2 b^2 ((d^2 - hi^2 - hr^2) (hi^2 + hr^2) + 
           c^2 (-2 d^2 + hi^2 + hr^2)))), 
  fr -> (a (-2 b^4 c d + 2 b^2 c d (c^2 + d^2) - b^5 hr + 
        b (c^2 - d^2)^2 hr + 2 b^3 hr (hi^2 + hr^2) - 
        2 c d (c^2 + d^2 - hi^2 - hr^2) (hi^2 + hr^2) - 
        b hr (hi^2 + hr^2)^2))/(b^4 (hi^2 + hr^2) + (c^2 + d^2 - hi^2 - 
         hr^2)^2 (hi^2 + hr^2) + 
      2 b^2 ((d^2 - hi^2 - hr^2) (hi^2 + hr^2) + c^2 (-2 d^2 + hi^2 + hr^2))),
   fi -> -((a b hi (b^2 + c^2 - d^2 - hi^2 - hr^2) (b^2 - c^2 + d^2 - hi^2 - 
          hr^2))/(b^4 (hi^2 + hr^2) + (c^2 + d^2 - hi^2 - hr^2)^2 (hi^2 + 
           hr^2) + 2 b^2 ((d^2 - hi^2 - hr^2) (hi^2 + hr^2) + 
           c^2 (-2 d^2 + hi^2 + hr^2)))), 
  gr -> (a (b^4 c hr - 2 b^2 c d^2 hr + c d^4 hr + 
        2 b^3 d (c^2 - hi^2 - hr^2) - c hr (-c^2 + hi^2 + hr^2)^2 - 
        2 b d (c^2 - hi^2 - hr^2) (c^2 - d^2 + hi^2 + hr^2)))/(b^4 (hi^2 + 
         hr^2) + (c^2 + d^2 - hi^2 - hr^2)^2 (hi^2 + hr^2) + 
      2 b^2 ((d^2 - hi^2 - hr^2) (hi^2 + hr^2) + c^2 (-2 d^2 + hi^2 + hr^2))),
   gi -> (a c hi (b^2 + c^2 - d^2 - hi^2 - hr^2) (b^2 - c^2 - d^2 + hi^2 + 
        hr^2))/(b^4 (hi^2 + hr^2) + (c^2 + d^2 - hi^2 - hr^2)^2 (hi^2 + 
         hr^2) + 2 b^2 ((d^2 - hi^2 - hr^2) (hi^2 + hr^2) + 
         c^2 (-2 d^2 + hi^2 + hr^2)))}} *)

Verifying,

eqns /. sol // Simplify

(* {True} *)

For a solution to exist, the RHS of all of these rules must be real

cons = Simplify[And @@ (FunctionDomain[#, params] & /@ sol[[1, All, 2]])]

(* (hi^2 + hr^2) (b^4 + (c^2 + d^2 - hi^2 - hr^2)^2) != 
 2 b^2 (c^2 (2 d^2 - hi^2 - hr^2) - (d^2 - hi^2 - hr^2) (hi^2 + hr^2)) *)

EDIT: When this constraint is not met, the variables do not have real values

Simplify[sol, (hi^2 + hr^2)*(b^4 + (c^2 + d^2 - hi^2 - hr^2)^2) ==
    2*b^2*(c^2*(2*d^2 - hi^2 - hr^2) - (d^2 - hi^2 - hr^2)*(hi^2 + hr^2))]

(* {{er -> ComplexInfinity, ei -> ComplexInfinity, fr -> ComplexInfinity, 
  fi -> ComplexInfinity, gr -> ComplexInfinity, gi -> ComplexInfinity}} *)
$\endgroup$
6
  • $\begingroup$ Solve produces a generic solution only. For example, (b^4 (hi^2 + hr^2) + (c^2 + d^2 - hi^2 - hr^2)^2 (hi^2 + hr^2) + 2 b^2 ((d^2 - hi^2 - hr^2) (hi^2 + hr^2) + c^2 (-2 d^2 + hi^2 + hr^2))) from er can be equal to zero. $\endgroup$
    – user64494
    Commented Sep 14 at 6:53
  • $\begingroup$ @user64494 - When the constraint is not met the variables do not have real values. $\endgroup$
    – Bob Hanlon
    Commented Sep 14 at 15:02
  • $\begingroup$ @user64494 - Using Reduce, i.e., Assuming[vars \[Element] Reals && params \[Element] Reals, Solve[eqns, vars, Method -> Reduce] // FullSimplify] gives an identical solution $\endgroup$
    – Bob Hanlon
    Commented Sep 14 at 15:07
  • $\begingroup$ I repeat that is a generic solution only: the denominators can be equal to zero, The command Reduce[eqns, vars, Reals] is running without any response for hours. $\endgroup$
    – user64494
    Commented Sep 14 at 16:49
  • $\begingroup$ But this approach just solves the set of linear equations then finds when the given solution exists through their domains. But this only gives a sufficient condition, not always necessary. This basically solves for when the coefficient matrix is invertible, but it needs not always be invertible for a solution to exist. For example if the constants are all 0. For example in the simplest case: imgur.com/a/08Fv18A, we see it requires bd != ae. but clearly this is not the only case when a solution exists, only when a unique solution exists. $\endgroup$
    – jujumumu
    Commented Sep 15 at 4:31
2
$\begingroup$

We can use CoefficientArrays to get coefficient matrix of the system:


eqs = 2 a*c + 2 d*fr + 2 b*er + 2 gi hi + 2 gr hr == 0 && 
   2 a*d + 2 c*fr + 2 b*gr + 2 (ei hi + er hr) == 0 && 
   2 a*b + 2 c*er + 2 d*gr + 2 (fi hi + fr hr) == 
    0 && (2 d*fi + 2 b*ei) + 2 gr*hi - 2 gi*hr == 
    0 && (2 c*fi + 2 b*gi) + 2 er hi - 2 ei hr == 
    0 && (2 c*ei + 2 d*gi) + 2 fr hi - 2 fi hr == 0;
vars = {er, ei, fr, fi, gr, gi};
consts = {a, b, c, d, hi, hr};

eqs = List @@ eqs;
{vec, mat} = CoefficientArrays[eqs, vars] // Normal;

And now LinearSolve:

varSolns = LinearSolve[mat, -vec]//FullSimplify

(*

{(a (2 b c (d - hi) (d + hi) (b^2 + c^2 - d^2 - hi^2) + 
    d ((b^2 - c^2)^2 - (d^2 - hi^2)^2) hr - 
    2 b c (b^2 + c^2 - 2 hi^2) hr^2 + 2 d (d - hi) (d + hi) hr^3 + 
    2 b c hr^4 - d hr^5))/(
 b^4 (hi^2 + hr^2) + (c^2 + d^2 - hi^2 - hr^2)^2 (hi^2 + hr^2) + 
  2 b^2 ((d^2 - hi^2 - hr^2) (hi^2 + hr^2) + 
     c^2 (-2 d^2 + hi^2 + hr^2))), -((
  a d hi (-(b^2 - c^2)^2 + (-d^2 + hi^2 + hr^2)^2))/(
  b^4 (hi^2 + hr^2) + (c^2 + d^2 - hi^2 - hr^2)^2 (hi^2 + hr^2) + 
   2 b^2 ((d^2 - hi^2 - hr^2) (hi^2 + hr^2) + 
      c^2 (-2 d^2 + hi^2 + hr^2)))), (
 a (-2 b^4 c d + 2 b^2 c d (c^2 + d^2) - b^5 hr + 
    b (c^2 - d^2)^2 hr + 2 b^3 hr (hi^2 + hr^2) - 
    2 c d (c^2 + d^2 - hi^2 - hr^2) (hi^2 + hr^2) - 
    b hr (hi^2 + hr^2)^2))/(
 b^4 (hi^2 + hr^2) + (c^2 + d^2 - hi^2 - hr^2)^2 (hi^2 + hr^2) + 
  2 b^2 ((d^2 - hi^2 - hr^2) (hi^2 + hr^2) + 
     c^2 (-2 d^2 + hi^2 + hr^2))), -((
  a b hi (b^2 + c^2 - d^2 - hi^2 - hr^2) (b^2 - c^2 + d^2 - hi^2 - 
     hr^2))/(b^4 (hi^2 + hr^2) + (c^2 + d^2 - hi^2 - hr^2)^2 (hi^2 + 
      hr^2) + 2 b^2 ((d^2 - hi^2 - hr^2) (hi^2 + hr^2) + 
      c^2 (-2 d^2 + hi^2 + hr^2)))), (
 a (b^4 c hr - 2 b^2 c d^2 hr + c d^4 hr + 
    2 b^3 d (c^2 - hi^2 - hr^2) - c hr (-c^2 + hi^2 + hr^2)^2 - 
    2 b d (c^2 - hi^2 - hr^2) (c^2 - d^2 + hi^2 + hr^2)))/(
 b^4 (hi^2 + hr^2) + (c^2 + d^2 - hi^2 - hr^2)^2 (hi^2 + hr^2) + 
  2 b^2 ((d^2 - hi^2 - hr^2) (hi^2 + hr^2) + 
     c^2 (-2 d^2 + hi^2 + hr^2))), (
 a c hi (b^2 + c^2 - d^2 - hi^2 - hr^2) (b^2 - c^2 - d^2 + hi^2 + 
    hr^2))/(b^4 (hi^2 + hr^2) + (c^2 + d^2 - hi^2 - hr^2)^2 (hi^2 + 
     hr^2) + 2 b^2 ((d^2 - hi^2 - hr^2) (hi^2 + hr^2) + 
     c^2 (-2 d^2 + hi^2 + hr^2)))}

*)

And confirm the solution (pretty much everything after this is the same as in @BobHanlon's answer):


ruleSolns = Thread[vars -> varSolns];
Simplify[eqs /. ruleSolns]

(* {True, True, True, True, True, True} *)

We can then combine the FunctionDomains of each solution over the reals with respect to constants const to find where the solution is defined:

Simplify[And @@ (FunctionDomain[#, consts, Reals] & /@ varSolns)]

(* 
(hi^2 + hr^2) (b^4 + (c^2 + d^2 - hi^2 - hr^2)^2) ≠ 
 2 b^2 (c^2 (2 d^2 - hi^2 - hr^2) - (d^2 - hi^2 - hr^2) (hi^2 + hr^2)) 
*)

Also, note that mat has a trivial NullSpace so the solutions are unique:

NullSpace[mat]
(* {} *)
$\endgroup$
1
  • $\begingroup$ But this approach just solves the set of linear equations then finds when the given solution exists through their domains. But this only gives a sufficient condition, not always necessary. This basically solves for when the coefficient matrix is invertible, but it needs not always be invertible for a solution to exist. For example if the constants are all 0. For example in the simplest case: imgur.com/a/08Fv18A, we see it requires bd != ae. but clearly this is not the only case when a solution exists, only when a unique solution exists. $\endgroup$
    – jujumumu
    Commented Sep 15 at 4:29
1
$\begingroup$

The command of 14.1 on Windows

Resolve[Exists[{er, ei, fr, fi, gr, gi}, 
2 a*c + 2 d*fr + 2 b*er + 2 gi hi + 2 gr hr == 0 && 
2 a*d + 2 c*fr + 2 b*gr + 2 (ei hi + er hr) == 0 && 
2 a*b + 2 c*er + 2 d*gr + 2 (fi hi + fr hr) == 
0 && (2 d*fi + 2 b*ei) + 2 gr*hi - 2 gi*hr == 
0 && (2 c*fi + 2 b*gi) + 2 er hi - 2 ei hr == 
0 && (2 c*ei + 2 d*gi) + 2 fr hi - 2 fi hr == 0], Reals]

produces the useless output which takes 15.5 MB in memory.

Addition. The above necessary and sufficient conditions of the existence of the solution can be simplified to 1.6 MB. It is still useless. A quite simple sufficient condition (but not a necessary one) of the existence of the solution consists in the following: the determinant of the matrix of the coefficients at {er, ei, fr, fi, gr, gi} does not equal zero (recall the Laplace's formulas).

Det[CoefficientArrays[{2 a c + 2 b er + 2 d fr + 2 gi hi + 2 gr hr == 
  0, 2 a d + 2 c fr + 2 b gr + 2 (ei hi + er hr) == 0, 
 2 a b + 2 c er + 2 d gr + 2 (fi hi + fr hr) == 0, 
 2 b ei + 2 d fi + 2 gr hi - 2 gi hr == 0, 
 2 c fi + 2 b gi + 2 er hi - 2 ei hr == 0, 
 2 c ei + 2 d gi + 2 fr hi - 2 fi hr == 0}, {er, ei, fr, fi, gr, 
 gi}][[2]]] != 0;
DullSimplify[%]

(hi^2 + hr^2) (b^4 + (c^2 + d^2 - hi^2 - hr^2)^2) != 2 b^2 (c^2 (2 d^2 - hi^2 - hr^2) - (d^2 - hi^2 - hr^2) (hi^2 + hr^2))

Edit. Correction if thr typos in the matrix of the coefficients at the variables, making use of @ydd code.

$\endgroup$
7
  • $\begingroup$ Hmm, I am interested in the necessary and sufficient conditions. How did you simplify it to 1.6 MB? $\endgroup$
    – jujumumu
    Commented Sep 15 at 5:51
  • $\begingroup$ First, I uses Simplify (FullSimplify is slow.). After that I apply FullSimplify.` $\endgroup$
    – user64494
    Commented Sep 15 at 13:37
  • $\begingroup$ if I make sscond the full simplified condition and run FindInstance[ Not[sscond] && a > 0 && b > 0 && c > 0 && d > 0, {a, b, c, d, hr, hi}, Reals] it says that it is not a quantified system of equations and inequalities. Do you know why this would be because it seems like it is too me. $\endgroup$
    – jujumumu
    Commented Sep 15 at 19:54
  • $\begingroup$ @jujumumu: What do you mean by " sscond the full simplified condition"? Please present the code to obtain it. $\endgroup$
    – user64494
    Commented Sep 16 at 8:48
  • $\begingroup$ cond = Resolve[Exists[{er, ei, fr, fi, gr, gi}, 2 ac + 2 dfr + 2 ber + 2 gi hi + 2 gr hr == 0 && 2 ad + 2 cfr + 2 bgr + 2 (ei hi + er hr) == 0 && 2 ab + 2 cer + 2 dgr + 2 (fi hi + fr hr) == 0 && (2 dfi + 2 bei) + 2 grhi - 2 gihr == 0 && (2 cfi + 2 bgi) + 2 er hi - 2 ei hr == 0 && (2 cei + 2 d*gi) + 2 fr hi - 2 fi hr == 0], Reals] sscond = FullSimplify[Simplify[cond]] $\endgroup$
    – jujumumu
    Commented Sep 17 at 4:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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