# Khan/khan-exercises

Switch branches/tags
Nothing to show
Fetching contributors…
Cannot retrieve contributors at this time
289 lines (274 sloc) 19.2 KB
 Systems of equations
randRangeNonZero(-6, 6) randRangeNonZero(-6, 6) randRangeNonZero(-6, 6) randRangeNonZero(-6, 6) randRangeNonZero(-9, 9) randRangeNonZero(-9, 9) (function() { var lcm = getLCM(abs(A1), abs(A2)); var m1 = lcm / abs(A1); var m2 = lcm / abs(A2); if (A1 * A2 > 0) { if (m1 === 1) { m2 *= -1; } else { m1 *= -1; } } return [m1, m2]; })() (function() { var lcm = getLCM(abs(B1), abs(B2)); var m1 = lcm / abs(B1); var m2 = lcm / abs(B2); if (B1 * B2 > 0) { if (m1 === 1) { m2 *= -1; } else { m1 *= -1; } } return [m1, m2]; })() abs(MULT_1 * MULT_2) < abs(MULT_3 * MULT_4) ? true : false XY_FLAG ? [MULT_1, MULT_2] : [MULT_3, MULT_4] C1 * (B1 * MULT_1 + B2 * MULT_2) - B1 * (C1 * MULT_1 + C2 * MULT_2) A1 * (B1 * MULT_1 + B2 * MULT_2) getGCD(X_NUMER1, X_DENOM1) X_NUMER1 / X_GCD X_DENOM1 / X_GCD C1 * MULT_3 + C2 * MULT_4 A1 * MULT_3 + A2 * MULT_4 C1 * MULT_1 + C2 * MULT_2 B1 * MULT_1 + B2 * MULT_2 getGCD(Y_NUMER1, Y_DENOM1) Y_NUMER1 / Y_GCD Y_DENOM1 / Y_GCD

Solve for x and y.

\begin{align*} expr(["+", ["*", A1, "x"], ["*", B1, "y"]]) &= C1 \\ expr(["+", ["*", A2, "x"], ["*", B2, "y"]]) &= C2 \end{align*}

x = X_NUMER2 / X_DENOM2

y = Y_NUMER / Y_DENOM

One way to solve this system of equations is to use elimination.

In order to eliminate \blue{x}, we need to make its coefficient in one equation equal to the negative of its coefficient for the other equation.

In order to eliminate \green{y}, we need to make its coefficient in one equation equal to the negative of its coefficient for the other equation.

\begin{align*} \blue{expr(["*", A1, "x"])} + \green{expr(["*", B1, "y"])} &= C1 \\ \blue{expr(["*", A2, "x"])} + \green{expr(["*", B2, "y"])} &= C2 \end{align*}

Multiply the top equation by MULT_A and the bottom equation by MULT_B.

\begin{align*} \blue{expr(["*", A1 * MULT_A, "x"])} + \green{expr(["*", B1 * MULT_A, "y"])} &= C1 * MULT_A \\ \blue{expr(["*", A2 * MULT_B, "x"])} + \green{expr(["*", B2 * MULT_B, "y"])} &= C2 * MULT_B \end{align*}

Add the top and bottom equations.

\green{expr(["*", Y_DENOM1, "y"])} = Y_NUMER1

Divide both sides by Y_DENOM1 and simplify.

\green{y = fractionReduce(Y_NUMER, Y_DENOM)}

Substitute \green{fractionReduce(Y_NUMER, Y_DENOM)} for \green{y} in the top equation.

\blue{expr(["*", A1, "x"])} + \green{B1}(\green{fractionReduce(Y_NUMER, Y_DENOM)}) = C1

\blue{expr(["*", A1, "x"])} + fractionReduce(B1 * Y_NUMER, Y_DENOM) = C1

\blue{expr(["*", A1, "x"])} = fractionReduce(C1 * Y_DENOM - B1 * Y_NUMER, Y_DENOM)

\blue{x = fractionReduce(X_NUMER, X_DENOM)}

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

Add the top and bottom equations.

\blue{expr(["*", X_DENOM2, "x"])} = X_NUMER2

Divide both sides by X_DENOM2 and simplify.

\blue{x = fractionReduce(X_NUMER2, X_DENOM2)}

Substitute \blue{fractionReduce(X_NUMER2, X_DENOM2)} for \blue{x} in the top equation.

\blue{A1}(\blue{fractionReduce(X_NUMER2, X_DENOM2)}) + \green{expr(["*", B1, "y"])} = C1

fractionReduce(A1 * X_NUMER2, X_DENOM2) + \green{expr(["*", B1, "y"])} = C1

\green{expr(["*", B1, "y"])} = fractionReduce(C1 * X_DENOM2 - A1 * X_NUMER2, X_DENOM2)

\green{y = fractionReduce(Y_NUMER, Y_DENOM)}

The solution is \blue{x = fractionReduce(X_NUMER2, X_DENOM2)}, \enspace \green{y = fractionReduce(Y_NUMER, Y_DENOM)}.

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

Solve for x and y.

\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

One way to solve this system of equations is by deriving an expression for y from the second equation, and substituting it back into the first equation.

Begin by subtracting expr(["*", A2, "x"]) from both sides of the second equation.

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

Divide both sides by B2 to isolate y.

y = \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 )(\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 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.

\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

One way to solve this system of equations is by deriving an expression for x from the second equation, and substituting it back into the first equation.

Begin by subtracting expr(["*", B2, "y"]) from both sides of the second equation.

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

Divide both sides by A2 to isolate x.

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

Substitute this expression for x in the first equation.

A1_SIGNabs( A1 )(\blue{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 x = fractionReduce(X_NUMER, X_DENOM),\enspace y = fractionReduce(Y_NUMER, Y_DENOM).