# Express variable in terms other variables when lots of equations are involved

Consider the following equations:

W*BP == X*PC
Y*AQ == Z*BQ
AC^2 == AB^2 + BC^2
PQ^2 == BP^2 + BQ^2
AP^2 == AB^2 + BP^2
BC == BP + PC
AB == AQ + BQ


Let's say, I want to express AC in terms of AP and PQ. Can I do that using Mathematica?

I know about Eliminate but I am not sure if it will work in this particular situation because a lot of equations are involved. Any help would be appreciated. :)

• Simplify[Eliminate[{W*BP==X*PC, Y*AQ==Z*QB, AC^2==AB^2+BC^2, PQ^2==BP^2+BQ^2, AP^2==AB^2+BP^2, BC==BP+PC, AB==AQ+QB}, {AB,BC,AQ,QB,BP,PC,BP,PC}]] will get you to AC^2*X^2==AP^2*X^2+PQ^2*W*(W+2*X)-BQ^2*W*(W+2*X) but it doesn't appear that you can get any further than that. Watch out for dividing by zero and for negative square roots.
– Bill
Aug 3, 2018 at 17:54
• Thanks @Bill. For some reason, I can't see the upvote button on besides your comment. It was very helpful. :) Aug 3, 2018 at 18:42
• There was a mistake in my question as I typed BQ and QB. After seeing your comment, I also realized that I actually don't want to eliminate W, X, Y, Z. Just out of curiosity, was it just a coincidence or was there some other reason why you dropped them out of the elimination process in your comment as well? Aug 3, 2018 at 18:52
• I started by Eliminating AB and BC and looked at the result. Then I included your undesired variables that showed up in that. And repeated. When I got down to trying the last few variables Eliminate would just return True instead of an equation eliminating those. So I stopped. Thus no deep knowledge or cunning plan on my part. I see my own typo in my solution where I included BP,PC twice. With the fixes I think the solution is PQ^2 W (W + 2 X) (Y + Z)^2 + AP^2 (-W (W + 2 X) Y^2 + X^2 Z (2 Y + Z)) == AC^2 X^2 Z (2 Y + Z)
– Bill
Aug 3, 2018 at 19:46
• Thank you very much for the help @Bill. I will happily accept it as an answer if you post it in the answers. Just one more question, what is the significance of Eliminate returning True? Does this mean it could not find a relation? Aug 3, 2018 at 19:59

Using the edited version of the question.

I did an experiment. AC^2==AB^2+BC^2 had the undesired AB and BC so I tried Eliminate on those two variables.

Eliminate[{W*BP == X*PC, Y*AQ == Z*BQ, AC^2 == AB^2 + BC^2, PQ^2 == BP^2 + BQ^2,
AP^2 == AB^2 + BP^2, BC == BP + PC, AB == AQ + BQ}, {AB, BC}]


giving

(*AQ^2 + 2 AQ BQ == AP^2 - BP^2 - BQ^2 && 2 BP PC + PC^2 == AC^2 - AP^2 &&
PQ^2 == BP^2 + BQ^2 && BP W == PC X && AQ Y == BQ Z && (AP^2 - BP^2 -
BQ^2) Y == BQ (AQ + 2 BQ) Z*)


which contained the undesired AQ and BQ so I included those in the Eliminate

Eliminate[{W*BP == X*PC, Y*AQ == Z*BQ, AC^2 == AB^2 + BC^2, PQ^2 == BP^2 + BQ^2,
AP^2 == AB^2 + BP^2, BC == BP + PC, AB == AQ + BQ}, {AB, BC, AQ, BQ}]


giving

(*2 BP PC + PC^2 == AC^2 - AP^2 && BP W == PC X && (-2 BP^2 + 2 PQ^2) Y Z +
(-BP^2 + PQ^2) Z^2 == (AP^2 - PQ^2) Y^2*)


which contains the undesired BP and PC so

Eliminate[{W*BP == X*PC, Y*AQ == Z*BQ, AC^2 == AB^2 + BC^2, PQ^2 == BP^2 + BQ^2,
AP^2 == AB^2 + BP^2, BC == BP + PC, AB == AQ + BQ}, {AB, BC, AQ, BQ, BP, PC}]


giving

(*W^2 (-AP^2 Y^2 + PQ^2 Y^2 + 2 PQ^2 Y Z + PQ^2 Z^2) + W X (-2 AP^2 Y^2 +
2 PQ^2 Y^2 + 4 PQ^2 Y Z + 2 PQ^2 Z^2) == X^2 Z (2 AC^2 Y - 2 AP^2 Y +
AC^2 Z - AP^2 Z)*)


It isn't really obvious how AP and PQ might relate to each other, so a little trial and error finds the following.

Simplify[Collect[
W^2 (-AP^2 Y^2 + PQ^2 Y^2 + 2 PQ^2 Y Z + PQ^2 Z^2) +
W X (-2 AP^2 Y^2 + 2 PQ^2 Y^2 + 4 PQ^2 Y Z + 2 PQ^2 Z^2) -
X^2 Z (2 AC^2 Y - 2 AP^2 Y + AC^2 Z - AP^2 Z) == 0, {AP, PQ}]]


which gives us

(*PQ^2 W (W + 2 X) (Y + Z)^2 +
AP^2 (-W^2 Y^2 - 2 W X Y^2 + X^2 Z (2 Y + Z)) ==
AC^2 X^2 Z (2 Y + Z)*)


Notice we now only have one equation left. So there isn't any way to add or subtract multiples of equations from each other to attempt to eliminate AC from that. You could try trading one of the other variables for AC to see if the result is more like what you want.

If you try to eliminate too many variables or your system has too much similarity in it then Eliminate can end up with expr==expr which must always be True and it will halt at that point giving you True as a result.

I hope this helps you understand the trial and error process that I used to get the result for you.

The task is underdefined, there are more variables than equations. One can express AC as a function of four variables, for example,

Eq = {W*BP == X*PC && Y*AQ == Z*QB && AC^2 == AB^2 + BC^2 &&
PQ^2 == BP^2 + BQ^2 && AP^2 == AB^2 + BP^2 && BC == BP + PC &&
AB == AQ + QB};
Solve[Eliminate[Eq, {AQ, W, Y, Z, WX, X, BC, AB, BP}], AC]
Out[]= {{AC -> -Sqrt[AP^2 + PC^2 - 2 Sqrt[-PC^2 (BQ^2 - PQ^2)]]}, {AC ->
Sqrt[AP^2 + PC^2 - 2 Sqrt[-PC^2 (BQ^2 - PQ^2)]]}, {AC -> -Sqrt[
AP^2 + PC^2 + 2 Sqrt[-PC^2 (BQ^2 - PQ^2)]]}, {AC -> Sqrt[
AP^2 + PC^2 + 2 Sqrt[-PC^2 (BQ^2 - PQ^2)]]}}

• Hi Alex, thank for the answer. :) How did you come up with the number 4 in "One can express AC as a function of four variables". Aug 3, 2018 at 18:42
• It's very simple: if you add another variable to the list for Eliminate[], then the output is True, and the set of solutions Solve[] is empty list {{}}. Aug 4, 2018 at 2:43