mldivide
Left matrix division, the backslash operator, for solving linear systems.
Category: Mathematics > Linear Algebra
Syntax
x = A\b
Solves A*x = b.
x = mldivide(A, b)
Function form of A\b.
Description
The backslash chooses a method from the shape of A: for a square matrix an LU factorization (a triangular solve if A is triangular, Cholesky if it is symmetric positive definite); for a non-square matrix a least-squares solution via QR.
It is the recommended way to solve systems, preferable to inv(A)*b. For several right-hand sides, pass them as columns of b in a single call.
Input arguments
A- Coefficient matrix. Square for an exact solve; rectangular for least squares.
b- Right-hand side with
size(A,1)rows. A scalarAdivides every element ofb.
Output arguments
x- The solution with
size(A,2)rows.
Example
Square, overdetermined and scalar cases
[2 1; 1 3] \ [3; 5]
[1 2; 3 4; 5 6] \ [1; 2; 3]
2 \ 6
Output
ans = 2×1
0.8000
1.4000
ans = 2×1
0
0.5000
ans = 3