Main Content

mrdivide, /

Solve systems of linear equations xA = B for x

Description

example

x = B/A solves the system of linear equations x*A = B for x. The matrices A and B must contain the same number of columns. MATLAB® displays a warning message if A is badly scaled or nearly singular, but performs the calculation regardless.

  • If A is a scalar, then B/A is equivalent to B./A.

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

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

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

Examples

collapse all

Solve a system of equations that has a unique solution, x*A = B.

A = [1 1 3; 2 0 4; -1 6 -1];
B = [2 19 8];
x = B/A
x = 1×3

    1.0000    2.0000    3.0000

Solve an underdetermined system, x*C = D.

C = [1 0; 2 0; 1 0];
D = [1 2];
x = D/C
Warning: Rank deficient, rank = 1, tol =  1.332268e-15.
x = 1×3

         0    0.5000         0

MATLAB® issues a warning but proceeds with calculation.

Verify that x is not an exact solution.

x*C-D
ans = 1×2

     0    -2

Input Arguments

collapse all

Operands, specified as vectors, full matrices, or sparse matrices. A and B must have the same number of columns.

  • If A or B has an integer data type, the other input must be scalar. Operands with an integer data type cannot be complex.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char
Complex Number Support: Yes

Output Arguments

collapse all

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

x is sparse only if both A and B are sparse matrices.

Tips

  • The operators / and \ are related to each other by the equation B/A = (A'\B')'.

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

Extended Capabilities

Introduced before R2006a