Language Reference


SOLVE Function

SOLVE (A, B);

The SOLVE function solves a system of linear equations.

The arguments to the SOLVE function are as follows:

A

is an $n \times n$ nonsingular matrix.

B

is an $n \times p$ matrix.

The SOLVE function solves the set of linear equations $\mb{AX}=\mb{B}$ for $\mb{X}$. The matrix $\mb{A}$ must be square and nonsingular.

The expression X = SOLVE(A,B) is mathematically equivalent to using the INV function in the expression X = INV(A)*B. However, the SOLVE function is recommended over the INV function because it is more efficient and more accurate.

The following example uses the SOLVE function:

A = {0 0 1 0 1,
     1 0 0 1 0,
     0 1 1 0 1,
     1 0 0 0 1,
     0 1 0 1 0};

 b = {9, 4, 10, 8, 2};

 /* solve linear system */
 x = solve(A,b);
 print x;

Figure 24.376: Solving a Linear System

x
3
1
4
1
5



The solution method that is used is discussed in Forsythe, Malcom, and Moler (1967). The SOLVE function uses a criterion to determine whether the input matrix is singular. See the INV function for details.

If $\mb{A}$ is an $n\times n$ matrix, the SOLVE function temporarily allocates an $n^2$ array in addition to the memory allocated for the return matrix.