Linear Algebra: solving a three-variable linear system with Excel or LibreOffice Calc
The tutor shows an example of how to solve a system of three equations using a spreadsheet.
Example: solve the system
- -3x + 2y + z = 16
- x – y – 3z = -19
- 2x + y + 7z = 30
Solution:
From linear algebra, this system becomes Aq = r, where A is the matrix
| -3 | 2 | 1 |
| 1 | -1 | -3 |
| 2 | 1 | 7 |
while q is the column vector
| x |
| y |
| z |
and r is the column vector
| 16 |
| -19 |
| 30 |
From
Aq=r
follows
A-1Aq=A-1r
Furthermore, since
A-1Aq=Iq=q
then
q=A-1r
So we need to perform the calculation A-1r on the spreadsheet.
My post from yesterday shows how to get A-1 (the inverse of matrix A). It’s short, but detailed.
Assuming you’ve produced A-1, it’s time to enter vector r:
| 16 |
| -19 |
| 30 |
Let’s imagine, on your spreadsheet, that A-1 resides in the range e1:g3, and that r resides in h1:h3. To multiply A-1 by r,
- Select a cell away from both ranges: k1, for example. Drag down to extend the selection from k1 to k3.
- Click to the formula bar and type =mmult(e1:g3,h1:h3). Don’t press enter.
- While holding down Ctrl and Shift, press Enter.
- (Note): With matrices, unlike numbers, the order of the multiplication matters: in Step 2, it must be =mmult(e1:g3,h1:h3), rather than h1:h3,e1:g3.
Hopefully you see the result
| -3 |
| 1 |
| 5 |
Therefore, x=-3, y=1, and z=5.
Source:
Johnson, Lee et al. Introduction to Linear Algebra. Don Mills: Addison-Wesley, 1989.
Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.