x = A\B solves
the system of linear equations A*x = B. The matrices A and B must
have the same number of rows. MATLAB^{®} displays a warning message
if A is badly scaled or nearly singular, but
performs the calculation regardless.

If A is a scalar, then A\B is
equivalent to A.\B.

If A is a square n-by-n matrix
and B is a matrix with n rows,
then x = A\B is a solution to the equation A*x
= B, if it exists.

If A is a rectangular m-by-n matrix
with m ~= n, and B is a matrix
with m rows, then A\B returns
a least-squares solution to the system of equations A*x=
B.

x = mldivide(A,B) is
an alternative way to execute x=A\B,
but is rarely used. It enables operator overloading for classes.

Solve a linear system of equations A*x
= b involving a singular matrix, A.

A = magic(4);
b = [34; 34; 34; 34];
x = A\b

Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =
1.306145e-17.
x =
1.5000
2.5000
-0.5000
0.5000

When rcond is between 0 and eps, MATLAB issues
a nearly singular warning, but proceeds with the calculation. When
working with ill-conditioned matrices, an unreliable solution can
result even though the residual (b-A*x) is relatively
small. In this particular example, the norm of the residual is zero,
and an exact solution is obtained, although rcond is
small.

When rcond is equal to 0,
the singular warning appears.

A = [1 0; 0 0];
b = [1; 1];
x = A\b

Warning: Matrix is singular to working precision.
x =
1
Inf

In this case, division by zero leads to computations with Inf
and/or NaN, making the computed result unreliable.

Solution, returned as a vector, full matrix, or sparse matrix.
If A is an m-by-n matrix
and B is an m-by-p matrix,
then x is an n-by-p matrix,
including the case when p==1.

If A has full storage, x is
also full. If A is sparse, then x has
the same storage as B.

If A is a square matrix, A\B is
roughly equal to inv(A)*B, but MATLAB processes A\B differently
and more robustly.

If the rank of A is less than
the number of columns in A, then x = A\B is
not necessarily the minimum norm solution. The more computationally
expensive x = pinv(A)*B computes the minimum norm
least-squares solution.

For full singular inputs, you can compute the least-squares
solution using the function linsolve.

The versatility of mldivide in solving linear
systems stems from its ability to take advantage of symmetries in
the problem by dispatching to an appropriate solver. This approach
aims to minimize computation time. The first distinction the function
makes is between full (also called "dense")
and sparse input arrays.

Algorithm for Full Inputs

The flow chart below shows the algorithm path when inputs A and B are full.

Algorithm for Sparse Inputs

If A is full and B is
sparse then mldivide converts B to
a full matrix and uses the full algorithm path (above) to compute
a solution with full storage. If A is sparse, the
storage of the solution x is the same as that of B and mldivide follows
the algorithm path for sparse inputs,
shown below.