We start with a system of three linear equations:
![]() |
(2) |
We'll use the coefficients of the variables to construct a square matrix. Next, we construct a matrix of solutions. This will yield the following matrices:
![]() |
(3) |
To do this in octave we type the following commands:
octave:27> A = [1, 2, 3; 2, 1, 1; 1, 1, -1;]
The returns the following formatted matrix:
A =
1 2 3
2 1 1
1 1 -1
To create the matrix of solutions we do the following:
octave:27> B = [20; 11; 1]
which returns this:
B =
20
11
1
It is important to note that semicolons, not commas, are used to distinguish the elements of the matrix. If instead we had typed:
octave:27> B = [20, 11, 1]
we would have created a 1 row by 3 column matrix.
Now we can use Octave to solve this system of equations. From our studies of matrix manipulation, we know that the inverse of a square matrix multiplied by the corresponding solution matrix will return the solution set of the system. We find the inverse matrix of A by doing:
octave:30> inv(A)
This returns
:
ans =
-0.28571 0.71429 -0.14286
0.42857 -0.57143 0.71429
0.14286 0.14286 -0.42857
To complete the process, we multiply the inverse with the solution matrix to yield:
octave:9> inv(A)*B
ans =
2.0000
3.0000
4.0000
You'll notice that the solutions are formatted as reals. This is a consequence of the floating point arithmetic required for calculations and is dependent upon the machine. Luckily, Octave has a shortcut function that does not require calculating the inverse matrix and then doing a separate multiplication operation. Use the backslash, or back division operator to calculate the solution:
octave:10> A \ B
ans =
2
3
4