\

Left division operator: solves the linear system A*x = B.

Category: Language Fundamentals > Operators and Elementary Operations

Syntax

X = A \ B

Solves A*X = B. Same as mldivide(A, B).

Description

For a square, nonsingular A, the system is solved by factorization (LU, or Cholesky and triangular shortcuts when the matrix has that structure). This is both faster and more accurate than inv(A)*B.

When A has more rows than columns, the result minimizes norm(A*X - B). With a scalar A, A \ B is just B / A.

Input arguments

A
Coefficient matrix, m-by-n.
B
Right-hand side with m rows. Each column is a separate system.

Output arguments

X
Solution with n rows. For a square A it satisfies A*X = B; otherwise it is the least-squares solution.

Example

A = [2 1; 1 3];
b = [3; 5];
x = A \ b
A * x
t = (0:3)';
[ones(4,1) t] \ [1; 3; 5; 7]
Output
x = 2×1

    0.8000
    1.4000
ans = 2×1

    3.0000
    5.0000
ans = 2×1

     1
     2

See also

mldivide / inv linsolve lsqminnorm