2. Systems of Linear Equations
§2.1 Introduction
No doubt you have encountered linear equations many times during your careers as students. Most likely, the very first equation you had to solve was linear. Yet despite their simplicity, systems of linear equations are of immense importance in mathematics and its applications to areas of physical sciences, economics, engineering and many many more. One of the purposes of linear algebra is to undertake a systematic study of linear equations. In this lab, we will use MATLAB to solve systems of linear equations. We will also learn about a very useful application of systems of linear equations to economics.
§2.2 Systems of Linear Equations
By now we have seen how a system of linear equations can be transformed into a matrix equation, making the system easier to solve. For example, the system

can be written the following way:
Now, by augmenting the matrix with the vector on the right and using row operations, this equation can easily be solved by hand. However, if our system did not have nice integer entries, solving the system by hand using row reduction could become very difficult. MATLAB provides us with an easier way to get an answer.
A system of this type has the form Ax = b, so we can enter these numbers into MATLAB using the following commands:
>> A = [2 -1 1; 1 2 3; 3 0 -1]
>> b = [8; 9; 3]
(Notice that for the column vector b, we include semicolons after each entry to ensure that the entries are on different rows; the command
>> b = [8 9 3]
would produce a row vector, which is not the same thing.)
The command
>> x = A\b
will find the solution (if it exists) to our equation Ax = b. In this case, MATLAB tells us
x =
2.0000
-1.0000
3.0000
Remark 2.1 Please take care in entering "A\b" command. It has a backslash "\" and NOT a forward slash "/".
Remark 2.2 The discrepancy in part (d) of the above exercise is simply due to rounding error. You'll notice that the error is a vector multiplied by a very small number, one on the order of 10-15. But why is there any error at all? After all, solving by row reduction gave very nice numbers, right? The reason is that MATLAB doesn't solve this problem the way you did. Instead, MATLAB uses complicated calculations to find the inverse of C, C-1, then finds the answer by the formula x = C-1*d. Some error is introduced when calculating C-1. You do not have to worry about inverses of matrices at this point, you will learn about this in the next lab.
There is a drawback, however, to solving systems of equations using the command "x = C\d". Let us explore that further.
|
|
Exercise 2.2 Consider the following system of equations:
-8x1 + 2x2 = 0 >> x = C\d Note the strange output. Include it in your write up. Now go ahead and solve this system by hand. How many free variables do you need to write down the solution? Based on your answer, can you explain why you got the error message when trying to use "x = C\d" command? |
To deal with the case of inconsistent systems or systems with infinitely many solutions, it may sometimes be better to use MATLAB to simply row-reduce your matrix and then read off the solutions. We happen to be very lucky since MATLAB has a command that performs Gaussian elimination for you.
| Exercise 2.3 | |
|
|
(a) Consider the following system of equations:
6x1 + 2x2 + 2x3 + 4x4 = 9 Enter the corresponding matrix C and the column vector d into MATLAB. Now we want to perform row reduction on the augmented matrix [C | d]. The command that performs row reduction in MATLAB is called "rref" (it stands for "reduced row echelon form"). Go ahead and type in >> rref([C d]) (Note that the command "[A B]" forms an augmented matrix [A | B] out of two matrices A and B with the same number of rows.) Based on your output write down the general solution to this system of equations. How many free variables are required? |
|
|
(b) Now, suppose we have the following system: x1
+ 2x2 + x3 - 2x4 = 3 As before enter the coefficient matrix C and the vector d into MATLAB and perform row reduction on the augmented matrix [C | d]. What are the solutions to this system? |
|
|
(c) For C and d as in part (b), enter
>> x = C\d Check that the output is really the solution to your system by typing in: >> C*x What answer did you expect to get and what did you really get? The moral of this exercise is "Be careful when using 'C\d' command!" |
§2.3 An Application to Economics: Leontief Models
Wassily Leontief (1906-1999) was a Russian-born, American economist who, aside from developing highly sophisticated economic theories, also enjoyed trout fishing, ballet and fine wines. He won the 1973 Nobel Prize in economy for his work in creating mathematical models to describe various economic phenomena. In the remainder of this lab we will look at a very simple special case of his work called a closed exchange model. Here is the premise:
Suppose in a far away land of Eigenbazistan, in a small country town called Matrixville, there lived a Farmer, a Tailor, a Carpenter, a Coal Miner and Slacker Bob. The Farmer produced food; the Tailor, clothes; the Carpenter, housing; the Coal Miner supplied energy; and Slacker Bob made High Quality 100 Proof Moonshine, half of which he drank himself. Let us make the following assumptions:
Everyone buys from and sells to the central pool (i.e. there is no outside supply and demand)
Everything produced is consumed
For these reasons this is called a closed exchange model. Next we must specify what fraction of each of the goods is consumed by each person in our town. Here is a table containing this information:
| Food | Clothes | Housing | Energy | High Quality 100 Proof Moonshine | |
| Farmer | 0.24 | 0.15 | 0.25 | 0.19 | 0.20 |
| Tailor | 0.15 | 0.27 | 0.18 | 0.16 | 0.05 |
| Carpenter | 0.22 | 0.20 | 0.21 | 0.26 | 0.10 |
| Coal Miner | 0.21 | 0.15 | 0.21 | 0.24 | 0.15 |
| Slacker Bob | 0.18 | 0.23 | 0.15 | 0.15 | 0.50 |
So for example, the Carpenter consumes 22% of all food, 20% of all clothes, 21% of all housing, 26% of all energy and 10% of all High Quality 100 Proof Moonshine.
|
|
Exercise 2.4 Note that the columns in this table all add up to 1. Explain why this happens. |
Now, let pF, pT, pC, pCM, pSB denote the incomes of the Farmer, Tailor, Carpenter, Coal Miner and Slacker Bob, respectively. Note that each of these quantities not only denotes the incomes of each of our esteemed citizens, but also the cost of the corresponding goods. So for example, pF is the Farmer's income as well as the cost of all the food. So if the Farmer produces $100 worth of food, then his income will also be $100 since all of this food is bought out and the profits go to the Farmer.
The idea is, of course, to be able to figure out how should we price the goods in order for the citizens of Matrixville to survive; i.e. we must find pF, pT, pC, pCM, and pSB subject to the following conditions:
0.24pF + 0.15pT + 0.25pC +
0.19pCM + 0.20pSB = pF
0.15pF + 0.27pT + 0.18pC + 0.16pCM +
0.05pSB = pT
0.22pF + 0.20pT + 0.21pC +
0.26pCM + 0.10pSB = pC
0.21pF + 0.15pT + 0.21pC + 0.24pCM +
0.15pSB = pCM
0.18pF + 0.23pT + 0.15pC + 0.15pCM +
0.50pSB = pSB
|
|
Exercise 2.5 Explain where this system of equations came from and what it means. (Think about what the left hand side and the right hand side of each equation mean.) |
Let us denote the column vector (pF, pT, pC, pCM , pSB)T by p, and let C be the coefficient matrix of the above system. We can now rewrite that system as
Cp = p
or equivalently
Cp - p = Cp - Ip = (C - I)p = 0
where I is the 5x5 matrix with 1's on the diagonal and 0's everywhere else. The property of the matrix I we are using is that Iv = v for any vector v.
| Exercise 2.6 | |
|
|
(a) Enter the matrices C and I into MATLAB.
>> C = [0.24 0.15 0.25 0.19 0.20; >> I = eye(5) Note that the command "eye(n)" creates an n x n matrix with 1's on the diagonal and 0's elsewhere. Let's also enter the zero vector: >> d = [0;0;0;0;0] |
|
|
(b) Use MATLAB to row reduce the augmented matrix [C - I | d] and write down the general solution to (C - I)p = 0. |
|
|
(c) What are the highest and the lowest priced commodities in Matrixville? List the inhabitants of this charming town in order of increasing income. If our friend Bob makes $40,000 per year, what are the incomes for the rest of the inhabitants? With all the moonshine that Bob drinks, do you think he will live long enough to enjoy his good life? |
§2.4 Conclusion
Systems of linear equations, though quite uncomplicated theoretically, show up in many interesting applications. Leontief's closed exchange model is only one of many such applications. Because systems of linear equations that arise in applications tend to be quite big and messy and not suitable to working with by hand, computer programs, such as MATLAB, turn out to be an indispensable tool for people who must work with such systems in their work.
Last Modified:
07/27/2008