Subtracting equations from each other?

An easy way to munge equations is to convert them to lists and then convert them back to equations when you are done munging. In your case, like so:

eq1 = -2 x + f[x, y[x]] - x^2 y[x]^3 == hy[y[x]]; 
eq2 = -2 E^(4 y[x]) + f[x, y[x]] - x^2 y[x]^3 == hx[x];
w1 = List @@ eq1;
w2 = List @@ eq2;
w3 = w1 - w2;
eq3 = Equal @@ w3

2 E^(4 y[x]) - 2 x == -hx[x] + hy[y[x]]


I'm going to guess that your actual goal here is to eliminate one of the terms shared by the two equations. In that case, you could also use Eliminate:

Eliminate[{eqfhx,eqhy},f[x,y[x]]]

$\text{hy}(y(x))-2 e^{4 y(x)}+2 x=\text{hx}(x)$

This doesn't do the subtraction exactly the way you asked for, but usually the goal of such a subtraction is to eliminate something. And that's why this may be the thing you actually need. It has the advantage that it will figure out how to do the subtraction all by itself.


You could use Inner, which is similar to Dot operation on matrices (but with operation of your choice not Times and Plus).

In the following code, the first element (LHS) of the first argument (eqhy) is subtracted by the first element (LHS) of the second argument (eqfhx), and second element (RHS) of the first argument (eqhy) is subtracted by the second element (RHS) of the second argument (eqfhx):

eqhy = -2 x + f[x, y[x]] - x^2 y[x]^3 == hy[y[x]];
eqfhx = -2 E^(4 y[x]) + f[x, y[x]] - x^2 y[x]^3 == hx[x];
Inner[Subtract, eqhy, eqfhx, Equal]

2 E^(4 y[x]) - 2 x == -hx[x] + hy[y[x]]

Tags:

Algebra