Linear Equations -- JHU MATLAB Help Page
LINEAR EQUATIONS
 

Creating a Matrix
Substituting Within a Symbolic Matrix
Manipulating Regular Matrices
Vectors
Scalar Multiplication
Addition of Matrices
Gauss-Jordan Elimination
Reduced Row-Echelon Form
Dot Product
Rank
Number of Solutions
Number of Solutions
How to Examples Exercise
How to:

The number of solutions of a system of linear equations is highly dependent upon the
rank of the coefficient matrix (That is, the part that normally comes before the equals sign in the equations. So, if we had 7x + 8y = 11, '7' and '8' would be part of the coefficient matrix, where as the '11' would not).
Suppose we have a system of equations with m equations (no. of rows in coefficient matrix) and n unknowns (no. of columns). First it is easy to see that the rank will always be less than or equal to m and n. This is because no matter what, we cannot have more leading 1's than we do rows or columns (whichever we have fewer of).

Case 1 - rank(A) = m, rank(A) = n
This can only happen we we are dealing with a square coefficient matrix. When we have a leading '1' in every row and every column, then our system of equations has exactly one solution.

Case 2 - rank(A) = m, rank(A) < n
Here we have a leading '1' in every row, but we have more columns than rows (more unknowns than equations). Here, we will have infinity many solutions.

Case 3 - rank(A) < m, rank(A) = n
Now we have a leading '1' in every column, but more columns than rows (more equations than unknowns). To find our number of solutions here, we must work with the augmented matrix (the coefficient matrix with the values that normally come after the equals sign; normally we separate the coefficient matrix from the last column with colons).
So, we enter our augmented matrix into MATLAB and we find its Reduced Row-Echelon Form. (note: MATLAB does not allow you to separate your coefficient matrix from the last column with a colon ':'. You just have to remember what it means yourself).
If every row below the row with the last leading '1' in the coefficient matrix is all zero's (including the last column), then we have exactly one solution.
However, if there exists a row with any non-zero value in the final column (the one that isn't part of our coefficient matrix), then our system of equations is inconsistent and we have no solutions.

Case 4 - rank(A) < m, rank(A) < n
Here, it is again necessary to look at our augmented matrix. If we have all-zero rows, we have infinitely many solutions.
But, if we have a row with a non-zero value in the final column, we again are inconsistent and have no solutions.


Examples:
Let's start with the equations '2x - y = 4' and 'x + 3y = 9'. So, we have 2 equations, 2 unknowns, and our coefficient matrix is R = [2 -1; 1 3]. MATLAB tells us rank(R) = 2. This is Case 1. Two columns, two rows, and our rank is two. So, we have exactly one solutions.

Now, let's only deal with the first equation '2x - y = 4'. Our coefficient matrix is quite simple, R = [2 -1]. We find out rank(R) = 1. So it is equal to the number of rows we have, but less than the number of columns. This is Case 2, and we have infinitely many solutions.

Let's get back our first two equations, but add a third equation into the mix, '3x - 2y = 3'. Our coefficient matrix is R = [2 -1; 1 3; 3 -2]. And, rank(R) = 2. This is Case 3, so now we must work with the augmented matrix, AM = [2 -1 4; 1 3 9; 3 -2 3]. When we put in AM = rref(AM), we see that the last row is '0 0 0'. So, we have exactly one solutions.

Now, we'll take our original two equations '2x - y = 4' and 'x + 3y = 9', but add in a new third equation 'x + y = 0'. Our coefficient matrix is R = [2 -1; 1 3; 1 1] and rank(R) = 2. This is again Case 3. So, we put in our augmented matrix, AM = [2 -1 4; 1 3 9; 1 1 0] and we find its RREF, AM = rref(AM). But this time, in the last row we have '0 0 -8'. So our system is inconsistent and we have no solutions.

This time we'll start with '2x - y = 4', but add to the mix '4x - 2y = 8' and '-2x + y = -4'. Our coefficient matrix is R = [2 -1; 4 -2; -2 1], and rank(R) = 1. So, our rank is less than both the number of rows and columns. This is Case 4, so we again look at the augmented matrix, AM = [2 -1 4; 4 -2 8; -2 1 -4]. In RREF we have '1 0 3' in the first row, and '0 0 0' in the second and third. So, we have infinitely many solutions.

One final example with '2x - y = 4', '4x - 2y = 8' and '-2x + y = 0'. Our coefficient matrix is exactly the same as in the previous example and has the same rank. But the augmented matrix, AM = [2 -1 4; 4 -2 8; -2 1 0], is different. In RREF the third row is also different, it is '0 0 4', and thus we have no solutions.


Exercise: