Accelerating the pace of engineering and science

# Documentation Center

• Trial Software
• Product Updates

# 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

expand all

### System of Equations

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.0000    2.0000    3.0000```

### Least-Squares on an Underdetermined System

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 =  6.280370e-16.

x =

0    0.5000         0
```

MATLAB issues a warning but proceeds with calculation.

Verify that x is not an exact solution.

`x*C-D`
```ans =

0    -2```

## Input Arguments

expand all

### A — Coefficient matrixvector | full matrix | sparse matrix

Coefficient matrix, specified as a vector, full matrix, or sparse matrix. If A has n columns, then B must have n columns.

Data Types: single | double
Complex Number Support: Yes

### B — Right-hand sidevector | full matrix | sparse matrix

Right-hand side, specified as a vector, full matrix, or sparse matrix. If B has n columns, then A must have n columns.

Data Types: single | double
Complex Number Support: Yes

## Output Arguments

expand all

### x — Solutionvector | full matrix | sparse matrix

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.

## More About

expand all

### Tips

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

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

## See Also

Was this topic helpful?