RunMat
  • Pricing
RunMat
GitHub
GitHub
DownloadSign InTry in Browser
DesktopRuntimeServer
RunMat

Run math blazing fast

GitHubX (Twitter)LinkedIn

Company

  • About
  • Pricing
  • Contact

Explore

  • RunMat for academia
  • RunMat vs MATLAB Online
  • Benchmarks

Get product updates and release notes from the RunMat team.

© 2026 Dystr · Made withfor the scientific community.

RunMat™ is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

LicensePrivacy
/
See all docs
Builtin Reference
    • cross
    • ctranspose
    • dot
    • mldivide
    • mpower
    • mrdivide
    • mtimes
    • pagemtimes
    • pagetranspose
    • trace
    • transpose

mrdivide — Solve linear systems with right-division in MATLAB and RunMat.

X = A / B (or mrdivide(A, B)) solves X * B = A. Square/nonsingular, rectangular, and rank-deficient solve paths follow MATLAB right-division semantics.

Syntax

X = mrdivide(A, B)

Inputs

NameTypeRequiredDefaultDescription
AAnyYes—Left-hand side matrix or scalar.
BAnyYes—Right coefficient matrix or scalar.

Returns

NameTypeDescription
XNumericArraySolution to X * B = A.

Errors

IdentifierWhenMessage
RunMat:mrdivide:InvalidInputInputs are unsupported or incompatible for right division.mrdivide: invalid input
RunMat:mrdivide:InternalRuntime cannot materialize right-division outputs.mrdivide: internal runtime failure

How mrdivide works

  • Scalars divide exactly: A / s scales A by 1/s, while s / B requires B to be scalar.
  • Logical matrix inputs are promoted to double precision. Integer participation is limited to the documented scalar-right form: same-class integer operands or an integer array with a scalar double use exact element-wise division and preserve the integer class; integer matrix solving is rejected.
  • Purely real operands produce real outputs; any complex operand promotes the computation (and result) to complex arithmetic.
  • Inputs must be effectively two-dimensional; trailing singleton dimensions are allowed.
  • The number of columns must agree (size(A, 2) == size(B, 2)), otherwise RunMat raises the MATLAB error "Matrix dimensions must agree."
  • Underdetermined and overdetermined systems return the minimum-norm least-squares solution.

Does RunMat run mrdivide on the GPU?

When a gpuArray provider is active, RunMat first offers the solve to its mrdivide hook. The WGPU provider currently downloads the operands to the host, executes the same SVD-based solver used by the CPU implementation, then uploads the result back to the device so residency remains transparent. If no provider is available—or the provider declines the request—RunMat gathers any gpuArray inputs to the host, computes the solution, and returns a host tensor.

GPU memory and residency

No manual care is required. If both operands already reside on the GPU and the provider supports mrdivide, the solve stays on the device. When the provider falls back to the host (the current WGPU implementation), the runtime seamlessly gathers data, executes the solve, and re-uploads the result to keep downstream GPU pipelines working as expected.

Examples

Solving a square linear system

A = [1 2; 3 4];
B = [5 6; 7 8];
X = A / B;

% Verify the solution
residual = X * B

Expected output:

X =
     3    -2
     2    -1

residual =
     1     2
     3     4

Computing a least-squares right division

A = [1 2 3];
B = [1 0 1; 0 1 1];
X = A / B

Expected output:

X = [1 2]

Dividing by a scalar

A = [2 4 6];
scaled = A / 2

Expected output:

scaled = [1 2 3]

Right division with complex inputs

A = [1+2i 3-4i];
B = [2-i 1+i];
X = A / B

Expected output:

X = -0.1429 - 0.2857i

Using 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 share the number of columns?⌄

Right division solves X * B = A; matrix multiplication requires size(A, 2) == size(B, 2).

What happens if B is singular or rectangular?⌄

RunMat matches MATLAB by computing the minimum-norm least-squares solution via singular-value decomposition—no explicit call to pinv is required.

Does mrdivide support higher-dimensional arrays?⌄

No. Inputs must be effectively matrices (trailing singleton dimensions are allowed). Use reshape or (:) to flatten higher-dimensional data before calling mrdivide.

How are logical or integer arrays handled?⌄

Logical matrices are promoted to double. Integer inputs are accepted only when the right operand is scalar, where A / B is equivalent to A ./ B, preserves the integer class, and retains resident output on the source provider.

How does RunMat handle NaN or Inf values?⌄

They propagate through the least-squares solve in the same way as MATLAB. NaNs in the inputs yield NaNs in the output wherever they influence the solution.

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 · eig · eigs · lu · qr · svd

Solve

cond · det · inv · linsolve · norm · null · pinv · rank · rcond · rref · vecnorm

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. 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 an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • How mrdivide works
  • Does RunMat run mrdivide on the GPU?
  • GPU memory and residency
  • Examples
  • Solving a square linear system
  • Computing a least-squares right division
  • Dividing by a scalar
  • Right division with complex inputs
  • Using mrdivide with coding agents
  • FAQ
  • Related Linalg functions
  • Ops
  • Structure
  • Factor
  • Solve
  • Open-source implementation
  • About RunMat