# Khan/khan-exercises

### Subversion checkout URL

You can clone with
or
.
Fetching contributors…

Cannot retrieve contributors at this time

197 lines (181 sloc) 16.384 kB
 Systems of equations
randRangeNonZero( -9, 9 ) randRangeNonZero( -9, 9 ) randRangeNonZero( -9, 9 ) randRangeNonZero( -9, 9 ) randRangeNonZero( -9, 9 ) randRangeNonZero( -9, 9 ) getLCM( abs( A1 ), abs( A2 ) ) ( A_LCM / abs( A1 ) ) * ( A1 * A2 > 0 ? -1 : 1 ) A_LCM / abs( A2 ) max( abs( MULT_1 ), abs( MULT_2 ) ) getLCM( abs( B1 ), abs( B2 ) ) ( B_LCM / abs( B1 ) ) * ( B1 * B2 > 0 ? -1 : 1 ) B_LCM / abs( B2 ) max( abs( MULT_3 ), abs( MULT_4 ) ) X_MAX < Y_MAX ? true : false (C1*(B1*MULT_1+B2*MULT_2)-B1*(C1*MULT_1+C2*MULT_2))/getGCD((C1*(B1*MULT_1+B2*MULT_2)-B1*(C1*MULT_1+C2*MULT_2)),(A1*(B1*MULT_1+B2*MULT_2))) (A1*(B1*MULT_1+B2*MULT_2))/getGCD((C1*(B1*MULT_1+B2*MULT_2)-B1*(C1*MULT_1+C2*MULT_2)),(A1*(B1*MULT_1+B2*MULT_2))) ( C1 * MULT_1 + C2 * MULT_2 ) / getGCD( C1 * MULT_1 + C2 * MULT_2, B1 * MULT_1 + B2 * MULT_2 ) ( B1 * MULT_1 + B2 * MULT_2 ) / getGCD( C1 * MULT_1 + C2 * MULT_2, B1 * MULT_1 + B2 * MULT_2 )

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)

The solution is\enspace x = fractionReduce( X_NUMER, X_DENOM ), \enspace 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 )

The solution is\enspace x = fractionReduce( X_NUMER, X_DENOM ), \enspace y = fractionReduce( Y_NUMER, Y_DENOM ).

A1 > 0 ? "" : "-" B1 > 0 ? "+" : "-" A2 / B2 > 0 ? "-" : "" A2 / B2 * B1 > 0 ? "-" : ""

Solve for x and y by deriving an expression for y from the second equation, and substituting it back into the first equation.

\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

Begin by moving the x-term in the second equation to the right side of the equation.

expr(["*", B2, "y"]) = \color{BLUE}{expr(["+", ["*", -A2, "x"], C2])}

Divide both sides by B2 to isolate y.

y = \color{BLUE}{SIGN_1decimalFraction( -A2 / B2, "true", "true" )x + decimalFraction( C2 / B2, "true", "true" )}

Substitute this expression for y in the first equation.

expr(["*", A1, "x"])B1_SIGNabs( B1 )(\color{BLUE}{SIGN_1decimalFraction( -A2 / B2, "true", "true" )x + decimalFraction( C2 / B2, "true", "true" )}) = C1

expr(["*", A1, "x"]) + SIGN_2decimalFraction( -A2 / B2 * B1, "true", "true" )x + decimalFraction( C2 / B2 * B1, "true", "true" ) = C1

Simplify by combining terms, then solve for x.

decimalFraction( A1 + ( -A2 / B2 * B1 ), "true", "true" )x + decimalFraction( C2 / B2 * B1, "true", "true" ) = C1

decimalFraction( A1 + ( -A2 / B2 * B1 ), "true", "true" )x = decimalFraction( C1 - ( C2 / B2 * B1 ), "true", "true" )

x = fractionReduce( X_NUMER, X_DENOM )

Substitute fractionReduce( X_NUMER, X_DENOM ) for x back into 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 )

The solution is\enspace x = fractionReduce( X_NUMER, X_DENOM ), \enspace y = fractionReduce( Y_NUMER, Y_DENOM ).

A1 > 0 ? "" : "-" B1 > 0 ? "+" : "-" A2 / B2 > 0 ? "-" : "" A2 / B2 * A1 > 0 ? "-" : ""

Solve for x and y by deriving an expression for x from the second equation, and substituting it back into the first equation.

\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

Begin by moving the y-term in the second equation to the right side of the equation.

expr(["*", A2, "x"]) = \color{ORANGE}{expr(["+", ["*", -B2, "y"], C2])}

Divide both sides by A2 to isolate x.

x = \color{ORANGE}{SIGN_1decimalFraction( -B2 / A2, "true", "true" )y + decimalFraction( C2 / A2, "true", "true" )}

Substitute this expression for x in the first equation.

A1_SIGNabs( A1 )(\color{ORANGE}{SIGN_1decimalFraction( -B2 / A2, "true", "true" )y + decimalFraction( C2 / A2, "true", "true" )}) + expr(["*", B1, "y"]) = C1

SIGN_2decimalFraction( -B2 / A2 * A1, "true", "true" )y + decimalFraction( C2 / A2 * A1, "true", "true" ) + expr(["*", B1, "y"]) = C1

Simplify by combining terms, then solve for y.

decimalFraction( B1 + ( -B2 / A2 * A1 ), "true", "true" )y + decimalFraction( C2 / A2 * A1, "true", "true" ) = C1

decimalFraction( B1 + ( -B2 / A2 * A1 ), "true", "true" )y = decimalFraction( C1 - ( C2 / A2 * A1 ), "true", "true" )

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)

The solution is\enspace x = fractionReduce( X_NUMER, X_DENOM ), \enspace y = fractionReduce( Y_NUMER, Y_DENOM ).

Something went wrong with that request. Please try again.