How to solve an equation on a given relation
To solve for x+y
you can simply do:
x + y /. Solve[x + y == 3 + 2 x + 2 y + 38/a, {x, y}][[1]]
-((38 + 3 a)/a)
To get an expression of the form x + y == ...
you can use Reduce
and post-process the output into desired form:
red = Reduce[{z == 3 + 2 x + 2 y + 38/a, z == x + y, a != 0}, z, {x, y}]
a != 0 && z == (-38 - 3 a)/a
red /. { a != 0 -> True, z -> x + y}
x + y == (-38 - 3 a)/a
This works for the example you posted. If you have a different example, where this does not work, will try to fix it. This checks that the combination of a x + b y
can factor out to a common x+y
term, otherwise it returns no solution.
solve[x_, y_, eq0_] := Module[{lhs, rhs, eq, cx, cy, sol = {}, z},
rhs = eq0 /. (lhs_ == rhs_) :> rhs;
lhs = eq0 /. (lhs_ == rhs_) :> lhs;
eq = rhs - lhs == 0;
cx = Last@CoefficientList[rhs - lhs, x];
cy = Last@CoefficientList[rhs - lhs, y];
If[cx == cy,
sol = (x + y) /. (First@Solve[(eq /. (cx x + cy y) -> z), z] /. z -> ( x + y));
sol = sol/cx
];
x + y == sol
];
Now call it as
ClearAll[x, y, a];
eq = x + y == 3 + 2 x + 2 y + 38/a;
solve[x, y, eq]
eq = x + y == 3 + 4 x + 4 y + 38/a;
solve[x, y, eq]
eq = 2 x + y == 3 - 2 x - 3 y + 38/a;
solve[x, y, eq]
This returns no solution, since can't collect x+y
into one term
eq = 2 x + y == 3 - 2 x - 1 y + 38/a;
solve[x, y, eq]