The most common tasks in numerical linear algebra are solving a set of linear equations of the form
Solving sets of linear equations
Several types of linear systems
- There may exist a unique vector
that solves (4.6). In that case, the system is called non-singular. An example of such a system is:
which has a unique solution
- There may be an infinite number of possible vectors
that solve (4.6). In that case, the system is called underdetermined. For example, the system
and many others.
- There may not be a vector
that solves (4.6). In that case, the system is called overdetermined. Examples of such systems are:
In MATLAB it is possible to determine the solution of a set of linear equations directly. For square or rectangular linear systems the method of first resort is the backslash operator. The solution of
is implemented directly in MATLAB as:
>> x = A\b
You can find more information about this command with
Sometimes MATLAB gives one of the following warnings after the command
>> Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = ....
>> Warning: Matrix is singular to working precision.
We will not go into the exact meaning of this warning. However, if this warning appears, you should not trust the result that appears on the screen.
If none of these error messages appears, this does not mean yet that the result that appears on the screen is the `real' solution of
. Namely, in case of overdetermined systems, a solution to this equation does not exist. MATLAB, however, will give the least squares `solution'.
Therefore, it is important to check the value of
given by MATLAB by typing in A*x, and comparing the result to the value of
, then a solution to the equations does not exist, and MATLAB has given the least squares 'solution'. If you do find
, you know that MATLAB has given a solution. However, there may still be more solutions. To find the general solution, you will have to use a different method, for example use the method explained below.
You can also use the command
A\b for symbolic matrices. A warning will be shown if the solution does not exist.