2
$\begingroup$

Here are some equations for illustration:

Format[Solve[{4*r1^3 == r2^2*(3*h), 
     t*r2^2*(h - d) == r2^2*(h + d)}, #] & /@ {{h, d}}, InputForm]

Here is their solution:

{{{h -> (4*r1^3)/(3*r2^2), d -> (4*r1^3*(-1 + t))/(3*r2^2*(1 + t))}}}

It is obvious that d -> h*(t - 1)/(t + 1) in above equation.

Is there any way to force Mathematica to output the results as:

{{{h -> (4*r1^3)/(3*r2^2), d -> h*(-1 + t))/(1 + t)}}}

This was a simple example but sometimes equations become too complicated and run for multiple lines. Figuring out a way to express one variable in terms of another will simplify them a lot.

Thanks. :)

$\endgroup$

2 Answers 2

2
$\begingroup$
(solh = Solve[{4*r1^3 == r2^2*(h - d + h + h + d), 
     t*r2^2*(h - d) == r2^2*(h + d)}, h, {d}]) // InputForm

(* {{h -> (4*r1^3)/(3*r2^2)}} *)

(sold = Solve[{4*r1^3 == r2^2*(h - d + h + h + d), 
      t*r2^2*(h - d) == r2^2*(h + d)}, d, MaxExtraConditions -> All] // 
    Quiet) // InputForm

(* {{d -> ConditionalExpression[
    (h*(-1 + t))/(1 + t), 
    (r2 == 0 && r1 == 0 && 1 + t != 0) || 
     (r2 != 0 && h == (4*r1^3)/(3*r2^2) && 
      1 + t != 0)]}} *)

sol = {solh, sold}[[All, 1, 1]] // Normal

(* {h -> (4 r1^3)/(3 r2^2), d -> (h (-1 + t))/(1 + t)} *)
$\endgroup$
3
  • $\begingroup$ Thanks @Bob. :) $\endgroup$ Commented Dec 14, 2020 at 6:29
  • $\begingroup$ Hi @Bob. I noticed that changing the order of variables I am trying to find changes the final result as well. For example, h, {d}] and d to d, {h}] and h results in completely different outputs. Why does this happen? $\endgroup$ Commented Dec 14, 2020 at 6:37
  • 2
    $\begingroup$ Solve[ ..., h, {d}] means solve for h while eliminating d. Solve[ ..., d, {h}] means solve for d while eliminating h. Solve[ ..., d, h] means solve for d and constrain it to the domain h. Since h is not a domain, you get a warning and it uses h as a variable to be eliminated, i.e., it interprets the statement as if you had entered Solve[ ..., d, {h}]. The elimination variable(s) even when just one are in List brackets to avoid initially being interpreted as a domain. $\endgroup$ Commented Dec 14, 2020 at 12:27
0
$\begingroup$

As r2 does not appear in your thought for solution, you could first eliminate r2 and then solve for d:

Solve[Eliminate[{4*r1^3 == r2^2*(3*h), t*r2^2*(h - d) == r2^2*(h + d)}, r2], d] // InputForm

(* {{d -> (-h + h*t)/(1 + t)}} *)
$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.