The SOLVE function solves a system of linear equations.
The arguments to the SOLVE function are as follows:
is an nonsingular matrix.
is an matrix.
The SOLVE function solves the set of linear equations for . The matrix 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;
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 is an matrix, the SOLVE function temporarily allocates an array in addition to the memory allocated for the return matrix.