4
$\begingroup$

First-time user of Mathematica. I have three equations, and I'm trying to solve for one of the variables. I'm hoping this is just a syntax problem.

eq1 = a^3*c + c^3*a == (a + (1 - f)*d)^3*b + b^3*(a + (1 - f)*d);
eq2 = g == c - b; 
eq3 = (e - d)/(a + d) == g/b;
Solve[{eq1, eq2, eq3}, d]

But it results in just empty output:

the result is just an empty squiggly-braces

$\endgroup$
4
  • 2
    $\begingroup$ In fact Solve should not yield the empty set of solutions. For more detailed discussion see e.g. What is the difference between Reduce and Solve?. We can get rid of trivial equation eq2 and set h in place of a + (1 - f)*d . Then use Reduce[{a^3 c + a c^3 == b^3 h + b h^3, (-d + e)/(a + d) == (c - b)/ b}, h] $\endgroup$
    – Artes
    Commented Mar 6 at 11:32
  • $\begingroup$ @Artes, that's some beneficial information. I was often frustrated with Solve not giving reasonable answers. This post goes in-depth into why this happens. Thanks! $\endgroup$
    – codebpr
    Commented Mar 6 at 13:02
  • $\begingroup$ @Artes Would I give h to to Reduce or d though? $\endgroup$ Commented Mar 6 at 15:08
  • $\begingroup$ It would be a bug if Solve did something different. $\endgroup$ Commented Mar 6 at 19:40

2 Answers 2

6
$\begingroup$
$Version

(* "14.0.0 for Mac OS X ARM (64-bit) (December 13, 2023)" *)

Clear["Global`*"]

eqns = {
   eq1 = a^3*c + c^3*a == (a + (1 - f)*d)^3*b + b^3*(a + (1 - f)*d),
   eq2 = g == c - b,
   eq3 = (e - d)/(a + d) == g/b};

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

(* {a, b, c, d, e, f, g} *)

Option 1: Solve for three variables (including d) and disregard unwanted solutions. For example,

sol1a = d -> # & /@ (d /. Solve[eqns, {d, a, b}]);

There are multiple lengthy solutions.

#[sol1a] & /@ {Length, LeafCount}

(* {3, 17664} *)

or,

sol1b = d -> # & /@ (d /. Solve[eqns, {d, b, c}]);

#[sol1b] & /@ {Length, LeafCount}

{6, 2215}

Option 2: Solve for d and eliminate two other variables. For example,

sol2a = Solve[eqns, d, {a, b}];

#[sol2a] & /@ {Length, LeafCount}

(* {3, 17667} *)

or,

sol2b = Solve[eqns, d, {b, c}];

#[sol2b] & /@ {Length, LeafCount}

(* {6, 2221} *)

Option 3: Solve for d and use the option MaxExtraConditions

(sol3 = SolveValues[eqns, d, MaxExtraConditions -> All])

enter image description here

$\endgroup$
2
  • $\begingroup$ Thanks, that's great. Could I narrow down the resulting solutions by assuming all the vars would be real numbers greater than zero? Also I'm trying to result in an equation which I can eventually type into python, so when the solution has several || and Root and #, then I don't even know where to begin with that. It seems that option 3 is closer to what I'm looking for, right? $\endgroup$ Commented Mar 6 at 21:22
  • $\begingroup$ Just include the constraints in the Solve, e.g., sol1c = d -> # & /@ (d /. Solve[Join[eqns, {vars \[Element] PositiveReals}], {d, a, b}]) // ToRadicals; $\endgroup$
    – Bob Hanlon
    Commented Mar 6 at 21:54
4
$\begingroup$

It's not a simple system of equations. There might be elegant methods. I present a more brute-force one:

eq4 = eq3 /. g -> (-b + c) // Simplify

c = c /. Solve[eq4, c][[1]]

Solve[eq1, d] // Simplify

Or using Eliminate to make it a one-liner:

Solve[Eliminate[{eq1, eq2, eq3}, {g, c}], d]

Or, as suggested by @Artes, using Reduce can even give some rational answers too instead of Root objects:

Reduce[Eliminate[{eq1, eq2, eq3}, {g, b}], d]

To convert Root objects to usual form just use ToRadicals. As an illustration:

sol = Reduce[Eliminate[{eq1, eq2, eq3}, {g, b}], d];

so[[3, 2, 1]] // ToRadicals
$\endgroup$
3
  • $\begingroup$ Did you mean Reduce[Eliminate[{eq1, eq2, eq3}, {g, b}], d]? Also can I reduce the number of solutions by telling it all my vars are >0? $\endgroup$ Commented Mar 6 at 16:04
  • $\begingroup$ And, I was hoping to just get a normal equation for d in terms of the other variables, however I get this long equation with boolean operators, so how do I even work with that? $\endgroup$ Commented Mar 6 at 16:30
  • $\begingroup$ @DansAltamira ah my mistake I forgot to add Reduce. The long equation actually contains root objects which you can easily convert to normal form using ToRadicals. And yes it is a better practice to define all the assumptions for your variables. If they are global variables used throughout the notebook you can use something like $Assumptions = {{a, b, c, d} \[Element] Reals, {a, b, c, d} > 0} or if they are local you just use Assuming within Solve. Let me edit my answer to highlight that. $\endgroup$
    – codebpr
    Commented Mar 7 at 2:06

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.