How to get solve to produce an answer if there are irrelevant equations?

Suppose I have a set of relations which I'd like to store as one variable.

setOfRelations = {x - y == 0, z - w == 0}


If I wish to obtain w in terms of the other variables in the system, I would have thought to do

Solve[setOfRelations, w]


with the expectation of {{w->z}}. Instead the output is {}. Obviously the irrelevant equations are messing up Solve.

What is the correct way to obtain some result given a set of relations, a subset of which may be coupled, and a subset of which may be irrelevant?

• Are the equations going to be linear or general polynomial relationships in the variables? Or possibly more complicated than polynomials?
– Hugh
Dec 24, 2018 at 7:32
• Maybe: Solve[setOfRelations, w, MaxExtraConditions -> All] Dec 24, 2018 at 7:59
• Solve[setOfRelations, w, {x}] or Solve[setOfRelations, w, {y}] Dec 24, 2018 at 14:52
• @Hugh The equations are always linear, and homogenous (equal to zero on right hand side). Dec 24, 2018 at 18:12

A direct approach is to delete relations without the required variables and then solve:

setOfRels[a_] := Select[setOfRelations, ! FreeQ[#, a] &]
Solve[setOfRels[w], w]


When in doubt, try Reduce

setOfRelations = {x - y == 0, z - w == 0}

Reduce[setOfRelations, w] // ToRules
(*{x -> y, w -> z}*)


But this generally gives you more than you ask for.