Main Content

mldivide, \

Symbolic matrix left division

Description

example

X = A\B solves the symbolic system of linear equations in matrix form, A*X = B for X.

If the solution does not exist or if it is not unique, the \ operator issues a warning.

A can be a rectangular matrix, but the equations must be consistent. The symbolic operator \ does not compute least-squares solutions.

X = mldivide(A,B) is equivalent to x = A\B.

Examples

System of Equations in Matrix Form

Solve a system of linear equations specified by a square matrix of coefficients and a vector of right sides of equations.

Create a matrix containing the coefficient of equation terms, and a vector containing the right sides of equations.

A = sym(pascal(4))
b = sym([4; 3; 2; 1])
A =
[ 1, 1,  1,  1]
[ 1, 2,  3,  4]
[ 1, 3,  6, 10]
[ 1, 4, 10, 20]
 
b =
 4
 3
 2
 1

Use the operator \ to solve this system.

X = A\b
X =
  5
 -1
  0
  0

Rank-Deficient System

Create a matrix containing the coefficients of equation terms, and a vector containing the right sides of equations.

A = sym(magic(4))
b = sym([0; 1; 1; 0])
A =
[ 16,  2,  3, 13]
[  5, 11, 10,  8]
[  9,  7,  6, 12]
[  4, 14, 15,  1]
 
b =
 0
 1
 1
 0

Find the rank of the system. This system contains four equations, but its rank is 3. Therefore, the system is rank-deficient. This means that one variable of the system is not independent and can be expressed in terms of other variables.

rank(horzcat(A,b))
ans =
3

Try to solve this system using the symbolic \ operator. Because the system is rank-deficient, the returned solution is not unique.

A\b
Warning: Solution is not unique because the system is rank-deficient. 
 
ans =
  1/34
 19/34
 -9/17
     0

Inconsistent System

Create a matrix containing the coefficient of equation terms, and a vector containing the right sides of equations.

A = sym(magic(4))
b = sym([0; 1; 2; 3])
A =
[ 16,  2,  3, 13]
[  5, 11, 10,  8]
[  9,  7,  6, 12]
[  4, 14, 15,  1]
 
b =
 0
 1
 2
 3

Try to solve this system using the symbolic \ operator. The operator issues a warning and returns a vector with all elements set to Inf because the system of equations is inconsistent, and therefore, no solution exists. The number of elements in the resulting vector equals the number of equations (rows in the coefficient matrix).

A\b
Warning: Solution does not exist because the system is inconsistent. 

ans =
 Inf
 Inf
 Inf
 Inf

Find the reduced row echelon form of this system. The last row shows that one of the equations reduced to 0 = 1, which means that the system of equations is inconsistent.

rref(horzcat(A,b))
ans =
[ 1, 0, 0,  1, 0]
[ 0, 1, 0,  3, 0]
[ 0, 0, 1, -3, 0]
[ 0, 0, 0,  0, 1]

Input Arguments

collapse all

Coefficient matrix, specified as a symbolic number, scalar variable, matrix variable, function, matrix function, expression, or vector or matrix of symbolic scalar variables.

Right side, specified as a symbolic number, scalar variable, matrix variable, function, matrix function, expression, or vector or matrix of symbolic scalar variables.

Output Arguments

collapse all

Solution, returned as a symbolic number, scalar variable, matrix variable, function, matrix function, expression, or vector or matrix of symbolic scalar variables.

Tips

  • Matrix computations involving many symbolic variables can be slow. To increase the computational speed, reduce the number of symbolic variables by substituting the given values for some variables.

  • When dividing by zero, mldivide considers the numerator’s sign and returns Inf or -Inf accordingly.

    syms x
    [sym(0)\sym(1), sym(0)\sym(-1), sym(0)\x]
    ans =
    [ Inf, -Inf, Inf*x]

Version History

Introduced before R2006a

expand all