Solving sets of linear equations

The most common tasks in numerical linear algebra are solving a set of linear equations of the form $ Ax = b$ .

Several types of linear systems

$\displaystyle Ax=b$ (4.3)

exist:
  1. There may exist a unique vector $ x$ that solves (4.6). In that case, the system is called non-singular. An example of such a system is:

    $\displaystyle \begin{pmatrix}1&2\\ 3&4\end{pmatrix} x=\begin{pmatrix}5\\ 6\end{pmatrix},$ (4.4)

    which has a unique solution $ x=\begin{pmatrix}-4\\ 4.5\end{pmatrix}$ .
  2. There may be an infinite number of possible vectors $ x$ that solve (4.6). In that case, the system is called underdetermined. For example, the system

    $\displaystyle \begin{pmatrix}1&2\\ 2&4\end{pmatrix} x=\begin{pmatrix}1\\ 2\end{pmatrix},$ (4.5)

    has solutions $ x=\begin{pmatrix}0\\ 0.5\end{pmatrix}$ , $ x=\begin{pmatrix}1\\ 0\end{pmatrix}$ and many others.
  3. There may not be a vector $ x$ that solves (4.6). In that case, the system is called overdetermined. Examples of such systems are:

    $\displaystyle \begin{pmatrix}1&2\\ 3&4\\ 5&6\end{pmatrix} x=\begin{pmatrix}5\\ 6\\ 8\end{pmatrix}$ (4.6)

    and

    $\displaystyle \begin{pmatrix}1&2\\ 2&4\end{pmatrix} x=\begin{pmatrix}1\\ 3\end{pmatrix}.$ (4.7)

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 $ Ax = b$ is implemented directly in MATLAB as:

>> x = A\b

You can find more information about this command with help mldivide.

Sometimes MATLAB gives one of the following warnings after the command A\b:

>> Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = ....
or

>> 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 $ Ax = b$ . 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 $ x$ given by MATLAB by typing in A*x, and comparing the result to the value of $ b$ . If $ Ax\neq b$ , then a solution to the equations does not exist, and MATLAB has given the least squares 'solution'. If you do find $ Ax = b$ , 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.



Previous      Next      Up      Contents


Subsections

Esteur 2010-03-22