Solve for x
and y
using elimination.
\begin{align*}expr(["+", ["*", A1, "x"], ["*", B1, "y"]]) &= C1 \\
expr(["+", ["*", A2, "x"], ["*", B2, "y"]]) &= C2\end{align*}
x
= X_NUMER / X_DENOM
y
= Y_NUMER / Y_DENOM
We can eliminate ( XY_FLAG ? "x" : "y" )
when its corresponding coefficients are negative inverses.
Recalling our knowledge of least common multiples, multiply the top equation by MULT_1
and the bottom equation by MULT_2
.
\begin{align*}expr(["+", ["*", A1*MULT_1, "x"], ["*", B1*MULT_1, "y"]]) &= C1*MULT_1\\
expr(["+", ["*", A2*MULT_2, "x"], ["*", B2*MULT_2, "y"]]) &= C2*MULT_2\end{align*}
Add the top and bottom equations.
expr(["*", B1*MULT_1+B2*MULT_2, "y"]) = C1*MULT_1+C2*MULT_2
Divide both sides by B1*MULT_1+B2*MULT_2
and reduce as necessary.
y = fractionReduce( Y_NUMER, Y_DENOM )
Substitute fractionReduce( Y_NUMER, Y_DENOM )
for y
in the top equation.
expr(["+", ["*", A1, "x"], ["*", B1, " " + fractionReduce( Y_NUMER, Y_DENOM )]]) = C1
expr(["+", ["*", A1, "x"], fractionReduce( B1 * Y_NUMER, Y_DENOM )]) = C1
expr(["*", A1, "x"]) = fractionReduce( C1 * Y_DENOM - B1 * Y_NUMER, Y_DENOM )
x = fractionReduce(X_NUMER,X_DENOM)
x = fractionReduce(X_NUMER,X_DENOM), y = fractionReduce( Y_NUMER, Y_DENOM )
Recalling our knowledge of least common multiples, multiply the top equation by MULT_3
and the bottom equation by MULT_4
.
\begin{align*}expr(["+", ["*", A1*MULT_3, "x"], ["*", B1*MULT_3, "y"]]) &= C1*MULT_3\\
expr(["+", ["*", A2*MULT_4, "x"], ["*", B2*MULT_4, "y"]]) &= C2*MULT_4\end{align*}
Add the top and bottom equations.
expr(["*", A1*MULT_3+A2*MULT_4, "x"]) = C1*MULT_3+C2*MULT_4
Divide both sides by A1*MULT_3+A2*MULT_4
and reduce as necessary.
x = fractionReduce( X_NUMER, X_DENOM )
Substitute fractionReduce( X_NUMER, X_DENOM )
for x
in the top equation.
expr(["+", ["*", A1, " " + fractionReduce( X_NUMER, X_DENOM )], ["*", B1, "y"]]) = C1
expr(["+", fractionReduce( A1 * X_NUMER, X_DENOM ), ["*", B1, "y"]]) = C1
expr(["*", B1, "y"]) = fractionReduce( C1 * X_DENOM - A1 * X_NUMER, X_DENOM )
y = fractionReduce( Y_NUMER, Y_DENOM )
x = fractionReduce( X_NUMER, X_DENOM ), y = fractionReduce( Y_NUMER, Y_DENOM )