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

mldivide — Solve linear systems with left-division in MATLAB and RunMat.

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

Syntax

X = mldivide(A, B)

Inputs

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

Returns

NameTypeDescription
XNumericArraySolution to A * X = B.

Errors

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

How mldivide works

  • Scalars divide exactly: s \ B scales B by 1/s, while A \ s requires A to be scalar.
  • Logical matrix inputs are promoted to double precision. Integer participation is limited to the documented scalar-left 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 return real outputs; any complex operand promotes the computation (and result) to complex arithmetic.
  • Inputs must behave like 2-D matrices; trailing singleton dimensions are allowed.
  • The number of rows must agree (size(A, 1) == size(B, 1)), otherwise RunMat raises the MATLAB error "Matrix dimensions must agree."
  • Underdetermined and overdetermined systems return the minimum-norm least-squares solution.

Does RunMat run mldivide on the GPU?

When a gpuArray provider is active, RunMat first offers the solve to its mldivide hook. The current WGPU provider downloads the operands to the host, executes the shared SVD-based solver, then uploads the result back to the device so downstream GPU pipelines keep their residency. If no provider is available—or a provider declines the request—RunMat gathers gpuArray inputs to the host, performs the solve there, and returns a host tensor.

GPU memory and residency

No manual residency management is required. If both operands already live on the GPU and the active provider implements mldivide, the solve stays on the device. When the provider falls back to the host (as the current WGPU backend does), RunMat gathers data, executes the same SVD solver used by the CPU implementation, and re-uploads the result so subsequent GPU work continues seamlessly. Exact integer scalar-left fallback likewise restores its integer result to the first resident input owner.

Examples

Solving a square linear system with backslash

A = [1 2; 3 4];
b = [5; 6];
x = A \ b

Expected output:

x =
    -4.0000
     4.5000

Computing a least-squares solution with backslash

A = [1 2; 3 4; 5 6];
b = [7; 8; 9];
x = A \ b

Expected output:

x =
    -6.0000
     6.5000

Scaling by a scalar using backslash

s = 2;
B = [2 4 6];
scaled = s \ B

Expected output:

scaled = [1 2 3]

Solving multiple right-hand sides at once

A = [4 1; 2 3];
B = [1 0; 0 1];
X = A \ B

Expected output:

X =
     0.3   -0.1
    -0.2    0.4

Left division with complex matrices

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

Expected output:

X =
   -0.0732 - 0.3415i
    0.8049 + 0.7561i

Using mldivide with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how mldivide changes the result.

Run a small mldivide example, explain the result, then change one input and compare the output.

FAQ

Why must A and B share the number of rows?⌄

Left division solves A * X = B, which requires size(A, 1) == size(B, 1) for matrix multiplication to be defined.

What happens if A is singular or rectangular?⌄

RunMat mirrors MATLAB by computing the minimum-norm least-squares solution using singular-value decomposition—no explicit pseudoinverse is necessary.

Does mldivide work with higher-dimensional arrays?⌄

Inputs must behave like matrices. Trailing singleton dimensions are allowed, but higher-rank arrays should be reshaped before calling mldivide.

How are logical or integer arrays treated?⌄

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

How does RunMat handle NaN or Inf values?⌄

NaNs and Infs propagate through the least-squares solver exactly as MATLAB does—any slice containing NaNs will typically produce NaNs in the corresponding output entries.

Is there a backslash() function?⌄

No. RunMat documents the matrix left-division operator A \\ B on the mldivide page, matching MATLAB's callable name and operator semantics.

Related Linalg functions

Ops

cross · ctranspose · dot · mpower · mrdivide · 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 mldivide is executed, line by line, in Rust.

  • View the source for mldivide 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 mldivide works
  • Does RunMat run mldivide on the GPU?
  • GPU memory and residency
  • Examples
  • Solving a square linear system with backslash
  • Computing a least-squares solution with backslash
  • Scaling by a scalar using backslash
  • Solving multiple right-hand sides at once
  • Left division with complex matrices
  • Using mldivide with coding agents
  • FAQ
  • Related Linalg functions
  • Ops
  • Structure
  • Factor
  • Solve
  • Open-source implementation
  • About RunMat