Introduction to Game Programming with C++ (Wordware Game Developers Library)

2.7 Simultaneous Linear Equations

The final subject to consider in this chapter is simultaneous linear equations, which is something of a mouthful when said aloud. The equations demonstrated so far contained only one unknown value that needed to be found, such asx+5=10.However, simultaneous equations are about solving for more than one unknown. Consider the following two equations:

From these equations we must solve for both x and y. This means we must find the values of both x and y. There are two methods for reaching the answer: substitution and elimination.

2.7.1 Solving by Substitution

One of the most common methods for reaching the solution is substitution. This method requires us to solve one of the equations. In other words, we take one of the two equations and isolate a single term on one side of the equals sign, either x or y, and thereby express its relationship to every other term in that equation. This solution is then substituted into the second equation to solve for the other variable. Consider the following:

First, consider equation 2:

Now substitute for x in equation 1.

Since x = 2 + y, and since y = 2, then x = 4.

Check this in equation 1:

2.7.2 Solving by Elimination

The second method for solving simultaneous equations is elimination, which is sometimes called the addition method. Here, both equations are combined into a single equation by either adding them together or subtracting them. The intention is to, by addition or subtraction, eliminate one of the other variable terms, either x or y, so that the resulting equation has only one term that must be solved. Afterward, the other term can be found through substitution. Consider the following equations:

Adding the two equations together will result in y being eliminated since y−y is 0. Remember, adding a negative number is the same as subtraction. The result follows.

The value x = 4 can be substituted in either of the original equations, as follows:

So x = 4, and y = 2.

Note 

There may be times when, given two equations with two unknowns, it may not be immediately possible to solve using the elimination method. This is because each equation may be such that, if added or subtracted, neither term (x or y) will be eliminated completely. In such cases, it is acceptable to multiply one or both equations until terms can be eliminated. For example:

Here, if these equations are added the result will still have x and y. Neither term will have been eliminated because 2x + x = 3x and −2y + y = −y. However, equation 1 can be multiplied by 2 to produce a third equation, as follows.

Now one term can be cancelled with addition:

  • (4x + 2y = 24) + (x− 2y = − 9)

  • 5x = 15

  • x = 3

Now substitute in equation 1:

  • 2x + y = 12

  • 6 + y = 12

  • y = 12 − 6

  • y = 6

So:

  • x = 3 and y = 6

Check this in equation 2:

  • x − 2y = −9

  • 3 − 12 = −9 (Correct)

Категории