mrdivide — Solve linear systems with matrix right division.
mrdivide(A, B) is the callable form of A / B and solves X * B = A for scalar, square, rectangular, rank-deficient, complex, and supported provider-resident inputs.
Syntax
X = mrdivide(A, B)Inputs
A- Type
Any- Required
- Yes
- Description
- Left numeric, logical, character, complex, or provider-resident operand.
B- Type
Any- Required
- Yes
- Description
- Right numeric, logical, character, complex, or provider-resident operand.
Returns
C- Type
NumericArray- Description
- Matrix-arithmetic result.
Errors
RunMat:mrdivide:InvalidInput- When
- Inputs are unsupported, are not matrices, or have incompatible dimensions.
- Message
mrdivide: unsupported operand types
RunMat:mrdivide:Internal- When
- The solver or acceleration provider cannot complete the operation correctly.
- Message
mrdivide: internal runtime failure
Right division
X = A / B and mrdivide(A, B) solve X * B = A. Square, rectangular, and rank-deficient inputs use a minimum-norm least-squares solve.
Both inputs must behave as matrices, with trailing singleton dimensions allowed. Nonscalar inputs must have the same number of columns.
Classes and scalar forms
A real pair returns a real floating result; a complex operand promotes the solve to complex arithmetic. Logical matrices are converted to double.
When B is scalar, A / B scales A by 1/B. Fixed-width integers are supported only in this scalar-right form, where the integer class is preserved. Integer matrix solving is rejected.
Acceleration
A resident solve is offered to the exact provider that owns its inputs. Mixed-residency operands are uploaded only when their class and precision can be represented by that owner.
A typed unsupported-operation response permits host fallback. Provider failures and invalid output metadata are surfaced rather than silently changing execution paths.
Examples
Solve a square system
A = [1 2; 3 4];
B = [5 6; 7 8];
X = A / B;
R = X * BExpected output:
R agrees with ACompute a least-squares right division
A = [1 2 3];
B = [1 0 1; 0 1 1];
X = A / BExpected output:
X = [1 2]Divide by a scalar
A = [2 4 6];
X = A / 2Expected output:
X = [1 2 3]Solve with complex inputs
A = [1+2i 3-4i];
B = [2-i 1+i];
X = A / B;
R = X * BExpected output:
R is the least-squares reconstructionUsing mrdivide with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how mrdivide changes the result.
Run a small mrdivide example, explain the result, then change one input and compare the output.
FAQ
Why must A and B have the same number of columns?⌄
The equation X * B = A requires both matrices to describe the same output columns.
What happens for singular or rectangular B?⌄
RunMat computes a minimum-norm least-squares solution with singular-value decomposition.
Are higher-dimensional arrays supported?⌄
Inputs must be effective matrices. Trailing singleton dimensions are allowed; reshape other arrays before solving.
How are logical and integer arrays treated?⌄
Logical matrices become double. Integer values are accepted only for scalar-right division and preserve the integer class.
Will a resident result stay on its provider?⌄
Yes when the provider returns a valid result or the documented scalar fallback can restore it to the exact input owner.
Related Linalg functions
Ops
cross · ctranspose · dot · mldivide · mpower · mtimes · pagemtimes · pagetranspose · trace · transpose
Structure
bandwidth · isdiag · ishermitian · issymmetric · istril · istriu · symrcm
Factor
chol · decomposition · decomposition.ctranspose · decomposition.mldivide · decomposition.mrdivide · decomposition.mtimes · decomposition.rdivide · decomposition.subsref · decomposition.times · decomposition.uminus · decomposition.uplus · eig · eigs · gmres · ichol · ilu · lu · ordeig · ordqz · ordschur · pcg · qr · qz · rsf2csf · schur · svd
Source you can read
Every RunMat function's source is public. Read exactly how mrdivide is executed, line by line, in Rust.
- View the source for mrdivide in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.