mrdivide - Solve systems of linear equations xA = B for
x - MATLAB ([original](https://in.mathworks.com/help/matlab/ref/double.mrdivide.html)) ([raw](?raw))
Solve systems of linear equations xA = B for_x_
Syntax
Description
[x](#btg5p6j-x) = [B](#btg5p6j-A)/[A](#btg5p6j-A)
solves the system of linear equations x*A = B
forx
. The matrices A
andB
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, thenB/A
is equivalent toB./A
. - If
A
is a squaren
-by-n
matrix andB
is a matrix withn
columns, thenx = B/A
is a solution to the equationx*A = B
, if it exists. - If
A
is a rectangularm
-by-n
matrix withm ~= n
, andB
is a matrix withn
columns, thenx
=
B
/A
returns a least-squares solution of the system of equationsx*A = B
.
[x](#btg5p6j-x) = mrdivide([B](#btg5p6j-A),[A](#btg5p6j-A))
is an alternative way to execute x
=
B
/
A
, but is rarely used. It enables operator overloading for classes.
Examples
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.
MATLAB® issues a warning but proceeds with calculation.
Verify that x
is not an exact solution.
Input Arguments
Operands, specified as vectors, full matrices, or sparse matrices.A
and B
must have the same number of columns.
- If
A
orB
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
Solution, returned as a vector, full matrix, or sparse matrix. IfA is anm
-by-n
matrix andB is a p
-by-n
matrix, then x
is ap
-by-m
matrix.
x
is sparse only if both A
andB
are sparse matrices.
Tips
- The operators
/
and\
are related to each other by the equationB/A = (A'\B')'
. - If
A
is a square matrix, thenB/A
is roughly equal toB*inv(A)
, but MATLAB processesB/A
differently and more robustly. - Use decomposition objects to efficiently solve a linear system multiple times with different right-hand sides.
decomposition
objects are well-suited to solving problems that require repeated solutions, since the decomposition of the coefficient matrix does not need to be performed multiple times.
Extended Capabilities
This function supports tall arrays with the limitation:
For the syntax Z = X/Y
, theY
operand must be a scalar.
For more information, see Tall Arrays for Out-of-Memory Data.
Usage notes and limitations:
- Code generation does not support sparse matrix inputs for this function.
- If the code generator determines that
A
is a scalar at compile time, thenB/A
is equivalent toB./A
.
Otherwise, even if the run-time value ofA
is a scalar, the code generator treatsA
as a matrix and requires the number of columns inA
andB
to be equal. So, ifB
has more than one column, the code generator produces an error.
Usage notes and limitations:
- Code generation does not support sparse matrix inputs for this function.
- If the code generator determines that
A
is a scalar at compile time, thenB/A
is equivalent toB./A
.
Otherwise, even if the run-time value ofA
is a scalar, the code generator treatsA
as a matrix and requires the number of columns inA
andB
to be equal. So, ifB
has more than one column, the code generator produces an error.
The mrdivide
function supports GPU array input with these usage notes and limitations:
- If
B
is rectangular, then it must also be nonsparse. - The MATLAB
mrdivide
function prints a warning ifB
is badly scaled, nearly singular, or rank deficient. ThegpuArray
mrdivide
is unable to check for this condition. Take action to avoid this condition.
For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Usage notes and limitations:
- If
B
is rectangular, then it must also be nonsparse. - The MATLAB
mrdivide
function prints a warning ifB
is badly scaled, nearly singular, or rank deficient. The distributed arraymrdivide
is unable to check for this condition. Take action to avoid this condition. - If
B
is an M-by-N matrix with N > M, for distributed arrays,mrdivide
computes a solution that minimizesnorm(X)
. The result is the same as the result ofPINV(B)*A
.
For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Version History
Introduced before R2006a