Mathematics |
Square Systems
The most common situation involves a square coefficient matrix A
and a single right-hand side column vector b
.
Nonsingular Coefficient Matrix
If the matrix A
is nonsingular, the solution, x = A\b
, is then the same size as b
. For example,
It can be confirmed that A*x
is exactly equal to u
.
If A
and B
are square and the same size, then X = A\B
is also that size.
It can be confirmed that A*X
is exactly equal to B
.
Both of these examples have exact, integer solutions. This is because the coefficient matrix was chosen to be pascal(3)
, which has a determinant equal to one. A later section considers the effects of roundoff error inherent in more realistic computations.
Singular Coefficient Matrix
A square matrix A is singular if it does not have linearly independent columns. If A is singular, the solution to AX = B either does not exist, or is not unique. The backslash operator, A\B
, issues a warning if A
is nearly singular and raises an error condition if it detects exact singularity.
If A is singular and AX = b has a solution, you can find a particular solution that is not unique, by typing
P
is a pseudoinverse of A. If AX = b does not have an exact solution, pinv(A)
returns a least-squares solution.
is singular, as you can verify by typing
Note
For information about using pinv to solve systems with rectangular coefficient matrices, see Pseudoinverses.
|
Exact Solutions. For b =[5;2;12]
, the equation AX = b has an exact solution, given by
You can verify that pinv(A)*b
is an exact solution by typing
Least Squares Solutions. On the other hand, if b = [3;6;0]
, then AX = b does not have an exact solution. In this case, pinv(A)*b
returns a least squares solution. If you type
you do not get back the original vector b
.
You can determine whether AX = b has an exact solution by finding the row reduced echelon form of the augmented matrix [A b]
. To do so for this example, type
Since the bottom row contains all zeros except for the last entry, the equation does not have a solution. In this case, pinv(A)
returns a least-squares solution.
General Solution | Overdetermined Systems |