Solutions of simultaneous equations

advertisement
Solutions of simultaneous equations
The HELM notes use Cramer’s rule to solve systems of linear equations but that method is computationally very inefficient, with many repeated subcalculations. The technique presented here - Gauss
elimination - usually is a lot faster, especially for large systems.
Consider the simultaneous equations
x+y
=
5
2x + 3y
=
13
Then y = 5 − x and so,
2x + 3(5 − x)
=
13
2x + 15 − 3x =
13
−x =
13 − 15 = −2
Therefore x = 2 and y = 5 − 2 = 3.
However, this approach becomes very messy when we have three or more variables. And, even worse,
you can easily “lose” information and get the wrong answer. Here is the sort of thing that can go wrong:
Consider the system of equations
2x + y + 3z
=
1
2x + 2y + 5z
=
4
x+y+z
=
1
x + 2y + 2z
=
3
It might be natural to take Equ 2 minus Equ 1 and then Equ 4 minus Equ 3 to give the two equations
y + 2z
=
3
y+z
=
2
Solving these equations gives y = 1 and z = 1. Plugging this back into the first equation gives 2x =
1 − y − z = 1 − 1 − 3 and hence
3
x=− .
2
Is this OK? NO! - these values, x = − 32 , y = 1, z = 1 don’t satisfy the third equation. So, what has
gone wrong? The problem is that we have not kept all the information from all 4 equations. So, we need
a method that reliably ensures that we don’t lose information. We use a method known as Gaussian
elimination.
1
Gaussian elimination
We are given a system of equations
ax
+
by
ex
+ fy
cz
+
···
=
+ gz
+
···
= k
+
d
···
Here a, b, c, d, e, · · · are constants and x, y, z, · · · are unknowns that we want to solve for.
At each step of the procedure we are allowed to do one of the following 3 operations:
(a) Add multiples of one equation to the others
(b) swop two equations
(c) multiply an equation by a (nonzero) number.
and then, crucially,
Write down all the resulting equations.
This last step is a little tedious but it does stop errors like the one we had above.
In doing this you can always reduce the system to Echelon Form, where each equation starts to the right
of the one above, followed perhaps by several equations of the form 0 = 0.
ax
···
+
by
+
cz
+
···
=
f 0y
+
g0 z
+
···
= k0
mz
+
nw
+ ···
=
d
p
···
Note that it is possible to get an equation of the form 0 = −1 or similar rubbish (that means that the
system of equations is inconsistent - there’s no solution). At this stage, we can easily solve the system by
back substitution where we start from the bottom equation and work upwards. There are 3 things that
can happen:
• You have an equation of the form 0 = − 12 . In this case there is No Solution.
• You have as many (nonzero) equations as unknowns. In this case you will have a Unique Solution
which you can pretty much write down (see the examples below).
• You have fewer equations than unknowns. In this case you have Infinitely Many Solutions. I
will explain below how you find them all.
2
Lets try this with the system we had before:
2x + y + 3z
=
1
2x + 2y + 5z
=
4
x+y+z
=
1
x + 2y + 2z
=
3
Since I don’t like fractions, I am going to first swop the first and fourth equation:
x + 2y + 2z
=
3
2x + 2y + 5z
=
4
x+y+z
=
1
2x + y + 3z
=
1
Now subtract twice Row 1 from the Rows 2 and 4 and subtract one copy of row one from Row 3 to give:
x + 2y + 2z
=
3
−2y + z
= −2
−y − z
= −2
−3y − z
= −5
Now using the second equation to eliminate the y’s from the last 2 equations gives:
x + 2y + 2z
=
3
−2y + z
= −2
− 23 z
= −1
− 52 z
= −2
And, finally taking equation 4 minus 5/3 times equation 3 gives
x + 2y + 2z
=
3
−2y + z
=
−2
− 23 z
=
−1
0
=
− 13
So, the last equation is impossible and explains why there is No solution.
3
Let’s do this with a few more examples. First, consider the system of equations
x + 2y + 3z
=
1
4x + 5y + 6z
=
1
2x + 5y + 7z
=
1
Before going through the Gaussian elimination, I am going to introduce some convenient notation. We
shall use the shorthand notation R1, R2, . . . to represent rows 1, 2, . . . and write for example R4 − R1 as
shorthand for “Replace Row 4 by Row 4 minus Row 1.” Secondly, we only need the numbers 1, 2, ..., 7, 1
so we will write down the Augmented matrix for the system; this consists of all the numbers, with a
vertical line in place of the equals sign. Here, though it is very important to put in a zero if some variable
does not occur. This gives:

1


 4

2
2
3
5
6
5
7
1



1 

1
Proceed by eliminating x from the second and third equations using row operation (a).




1 2 3 1
1
2
3 1








 4 5 6 1  R2 − 4R1 ∼  0 −3 −6 −3  .




R3 − 2R1
2 5 7 1
0
1
1 −1
Next we divide row 2 by (-3) to produce:

1
2
3 1


 0 −3 −6 −3

0
1
1 −1


1




∼ 0

 − 1 R2

3
0
2
3
1
2
1
1
1



1 .

−1
Finally, we get

1


 0

0
2
3
1
2
1
1
1


1




∼ 0
1 


0
−1
R3 − R2
Reverting to a system of equations we see that
x + 4y + 2z
=
3
y + 2z
=
1
−z
4
= −2
2
3
1
2
0
−1
1



1 

−2
Solving from the bottom up this gives
z
=
2
y
= −1 − z = −3
x
=
1 − 2y − 3z = 1 + 6 − 6 = 1
The next thing I should explain is what to do when you end up with fewer equations than unknowns in
echelon form. For example, one might have:
x + y
+ z
+
w
=
2
z
+
3w
=
5
In this case, if I add in two equations y = 27 and w = 34 (or any other numbers) then I would have a
system of equations in echelon form with the same number of equations as unknowns, and I could solve
uniquely. So, we do something similar. The rule is:
• If you are in echelon form and have fewer equations than unknowns, for each variable
that does not appear at the beginning of an equation, put that equation equal to an
arbitrary constant and then solve (uniquely) for the others.
So, in our example this gives
w
= a
z
=
y
= b
x
=
5 − 3w = 5 − 3a
2 − y − z − w = 2 − b − (5 − 3a) − a = −3 − b + 2a
Lets do one more example:
−2x +
z
+
w
= −3
+
w
=
2
5
x +
y
+
z
x +
y
−
2z
− 2w
=
−3x +
y
+
4z
+
= −5
4w
We write in echelon form then swop rows one and two to get:



−2 0
1
1
−3
1 1






 1 1
 −2 0
1
1
2 



∼



 1 1 −2 −2
 1 1
5 



−3 1
4
4
−5
−3 1
5
1
1
1
1
−2
−2
4
4
2



−3 


5 

−5
Now keep doing row

1


 −2


 1

−3

1


 0


 0

0

1


 0


 0

0
operations to get
1
1
1
0
1
1
1
−2
−2
1
4
4
1
1
1
2
3
3
0
−3
−3
4
7
7
1
1
1
2
3
3
0
−3
−3
0
1
1


2


−3  R2 + 2R1


5  R3 − R1

r4 + 3R1
−5



1 


3 

R4 − 2R2
1
2


 0


 0

0
∼

2
1


 0


 0

0
∼




1 


3 

−1
R4 + 13 R3
1
1
1
2
3
3
0
−3
−3
4
7
7
1
1
1
2
3
3
0 −3
−3
0
1


 0


 0

0
∼
1
1
2



1 


3 

1
2



1 


3 

−1
1
1
1
1
2
3
3
0
−3
−3
0
0
0
2



1 


3 

0
Thus, we have the system
x +
y
+
z
+
w
=
2
2y
+
3z
+
3w
=
1
− 3w
=
3
−3z
So, we can put w equal to an arbitrary number, as w does not appear at the beginning of any of these
equations. Thus, we get solutions
w
= c
z
= −1 − w = −1 − c
2y
=
1 − 3(−1 − c) − 3c
x
=
2 − y − z − w = 1.
6
or
y=2
Finally, let’s do an example from networks. Consider the following flow network


5y
10
x
−−−−→ •A −−−−→


wy
10
•B −−−−→


yy
20
z
5
−−−−→ •D −−−−→ •C ←−−−−


30y
You are asked to find the possible flows x, y, z, w.
The rule is that the flow into any node has to be the same as the flow out. Thus from the 4 nodes we
get the equations:
A
15 = x + w
B:
10 + y = x
or
C:
y + z = 30 − 5 = 25
D:
20 + w = z
or
x − y = 10
z − w = 20
I will leave the details to you but upon reducing to echelon form this gives the equations
x +
x −
w
y
y
+
z
z
− w
=
15
=
10
=
25
=
20
with solutions:
w = c,
y = 5 − c,
z = 20 + c,
x = 15 − c.
If you think about it, it is reasonable that you have an infinite number of solutions, since one can increase
the flow around the middle circuit without causing a problem.
Finally, for an application to electrical circuits, please read the HELM notes “Engineering Example 3”
on Page 9 of the notes “8.3: Solution by Gaussian Elimination.” The rule, here, is Kirchhoff’s Law which
says that the voltage drop around any circuit is exactly zero. Also, the drop across a resistor of x Ohms
is xi, where i is the current (note that this is not the square root of minus one—it is the notation they
use in Electrical engineering...) Now you will be able to follow those explanations on those HELM notes.
Other techniques
There are (at least) two other techniques that also work for some systems.
7
The first is Cramer’s Rule This is described in the HELM notes and is quite good for a system of
3 equations in 3 unknowns that has a solution. However for bigger systems it is Very Very slow. For
systems that have infinitely many solutions it does not work. So I strongly advise you not to use it.
The second amounts to finding the “inverse of the coefficient matrix” (the words will be defined next
week). Once again, it is quite good for a system of 3 equations in 3 unknowns that has a solution.
However for bigger systems it is Very Very slow. For systems that have infinitely many solutions it does
not work. So I strongly advise you not to use it.
8
Download