> with(linalg);
Consider the following system of linear equations:
x + 2 y + 4 z = 5
x + 3 y + 9 z = 6
x + 4 y + 16z = 7
Its matrix of coefficients is:
> A:=matrix([[1, 2, 4], [1, 3, 9],[1, 4, 16]]);
A := |
[ 1 |
2 |
4 ] |
[ 1 |
3 |
9 ] |
[ 1 |
4 |
16 ] |
The determinant of this matrix is
> d:=det(A);
d := 2
Since d is not 0, A is invertible and we can use Cramer's rule. Take matrix A1
by replacing the first column in A by the column of right sides:
> A1:=matrix([[5,2,4],[6,3,9],[7,4,16]]);
A1 := |
[ 5 |
2 |
4 ] |
[ 5 |
3 |
9 ] |
[ 7 |
4 |
16 ] |
Here is the determinant of A1:
> d1:=det(A1);
d1 := 6
So we can find x:
> x:=d1/d;
x := 3
Now we form A2 by replacing the second column of A by the vector b:
> A2:=matrix([[1,5,4],[1,6,9],[1,7,16]]);
A2 := |
[ 1 |
5 |
4 ] |
[ 1 |
6 |
9 ] |
[ 1 |
7 |
16 ] |
Here is the determinant of A2:
> d2:=det(A2);
d2 := 2
And we can find y:
> y:=d2/d;
y := 1
A similar procedure to find z:
> A3:=matrix([[1,2, 5],[1, 3, 6], [1, 4, 7]]);
A3 := |
[ 1 |
2 |
5 ] |
[ 1 |
3 |
6 ] |
[ 1 |
4 |
7 ] |
> d3:=det(A3);
d3 := 0
> z:=d3/d;
z := 0
So we got the following solution of our system of equations:
x=3, y=1, z=0
One can check that these numbers satisfy our system of equations.