Example 1
Clear[a,b,aI]
a={{1,2,3},{2,5,3},{1,0,8}};
b={{1},{6},{-6}};
MatrixForm[a]
MatrixForm[b]
Out[2]=
1 2 3 2 5 3 1 0 8
Out[3]=
1 6 -6
Form a matrix, called the augmented matrix and denoted [A,b] by adjoining the vector b to the right of the matrix A.
In[4]:=
ab=AppendRows[a,b];
MatrixForm[ab]
Out[4]=
1 2 3 1 2 5 3 6 1 0 8 -6
There is one important underlying idea here.
ELEMENTARY ROW OPERATIONS ON THE AUGMENTED MATRIX DO NOT AFFECT SOLUTIONS.
Theorem: Any finite sucession of elementary row operations on [A,b] produces the augmented matrix of a system that is equivalent to Ax=b.
If you think about how you were taught to solve these systems, you just did elementary row operations (although you may not have recognized it at the time).
In[5]:=
MatrixForm[RowReduce[ab]]
Out[5]=
1 0 0 2 0 1 0 1 0 0 1 -1
Now we are solving the system Ix=Transpose{2,1,-1}, which is much easier to solve. The idea here is an extension of the LU factorization (Gaussian Elimination) idea. Reduce your system to one with the same solution that is easier to solve. The solution in our example is obviously x=Transpose{2,1,-1}.
Notice that the GJSF of a is the identity matrix. Remember that this means a in nonsingular so it must have a unique solution, corresponding to Inverse[a].b
In[6]:=
aI=AppendRows[a,IdentityMatrix[3]];
RowReduce[aI];
MatrixForm[RowReduce[aI]]
inva=TakeColumns[RowReduce[aI],-3];
MatrixForm[inva]
Out[6]=
1 0 0 -40 16 9 0 1 0 13 -5 -3 0 0 1 5 -2 -1
Out[7]=
-40 16 9 13 -5 -3 5 -2 -1
In[8]:=
inva.b
Out[8]=
{{2}, {1}, {-1}}
This is indeed our solution.
We saw using LU factorization, that it is possible to solve for more than one b value without refactoring. We can solve for more than one b value using GJSF; simply append all the b values you wish to solve for:
Solve Ax=b and Ax=c for A and b above and c=Transpose{4,5,9}:
In[9]:=
Clear[a,b,c]
a={{1,2,3},{2,5,3},{1,0,8}};
b={{1},{6},{-6}};
c={{4},{5},{9}};
In[10]:=
abc=AppendRows[a,b,c];
MatrixForm[abc]
Out[10]=
1 2 3 1 4 2 5 3 6 5 1 0 8 -6 9
In[11]:=
MatrixForm[RowReduce[abc]]
Out[11]=
1 0 0 2 1 0 1 0 1 0 0 0 1 -1 1
The solution of Ax=b is Transpose{2, 1, -1} and the solution to Ax=c is Transpose{1, 0, 1}.