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
    • binornd
    • bootstrp
    • datasample
    • dividerand
    • exprnd
    • gamrnd
    • lhsdesign
    • mvnrnd
    • normrnd
    • random
    • randsample
    • rng
    • trnd
    • unidrnd
    • unifrnd
    • wblrnd

mvnrnd — Generate multivariate normal random samples.

mvnrnd(mu,Sigma) draws rows from one or more multivariate normal distributions. mu supplies mean vectors and Sigma supplies covariance matrices.

Syntax

r = mvnrnd(mu, Sigma)
r = mvnrnd(mu, Sigma, n)

Inputs

NameTypeRequiredDefaultDescription
muNumericArrayYes—Mean vector or matrix with one mean vector per row.
SigmaNumericArrayYes—Covariance matrix or covariance matrix pages.
nNumericArrayNo—Number of random rows to draw when mu is a single mean vector.

Returns

NameTypeDescription
rNumericArrayRandom samples with observations in rows.

Errors

IdentifierWhenMessage
RunMat:mvnrnd:InvalidArgumentInputs are malformed, dimensions are incompatible, or covariance pages are not symmetric positive semidefinite.mvnrnd: invalid argument
RunMat:mvnrnd:InternalRunMat cannot allocate or construct the requested random samples.mvnrnd: internal operation failed

How mvnrnd works

  • mu can be a scalar, a vector, or an m-by-d matrix with one mean vector per row. A d-by-1 column vector is treated as d one-dimensional means.
  • Sigma can be a d-by-d covariance matrix, a 1-by-d diagonal-variance vector, a d-by-d-by-m array of covariance pages, or a 1-by-d-by-m array of diagonal-variance pages.
  • mvnrnd(mu,Sigma,n) draws n rows when mu is a single mean vector and Sigma has one covariance page; n must be a positive scalar integer.
  • Current MATLAB documents single and double mu, Sigma, and n values. Typed integers and logical inputs are independently gated RunMat extensions; integer distribution values must be exactly representable as double.
  • A single mu or Sigma selects single output; otherwise output is double. Integer n is structural and does not select output class or residency.
  • Without n, RunMat draws one row for each row of mu, each page of Sigma, or their shared row/page count.
  • A single covariance matrix is reused for all rows of matrix mu; a single mean vector is reused for all covariance pages.
  • Sigma must be symmetric positive semidefinite. Positive-definite covariances use Cholesky; singular semidefinite covariances use a symmetric eigen factor.
  • All distribution inputs must be real finite numeric values, and outputs place observations in rows.

Examples

Draw five bivariate samples

rng('default');
R = mvnrnd([1 2], [4 1; 1 9], 5)

Use one covariance page per mean row

mu = [0 0; 10 20];
Sigma = cat(3, eye(2), [4 0; 0 9]);
R = mvnrnd(mu, Sigma)

Use diagonal variances

R = mvnrnd([1 2], [4 9], 5)

Draw from a singular covariance

R = mvnrnd([0 0], [1 1; 1 1], 3)

Using mvnrnd with coding agents

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

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

FAQ

Does mvnrnd use the same RNG as randn and normrnd?⌄

Yes. RunMat draws standard normal variates from the shared deterministic RNG state, so rng controls reproducibility.

Does RunMat require Sigma to be positive definite?⌄

No. Positive semidefinite covariance matrices are accepted. Negative eigenvalues outside numerical tolerance raise an error.

Related Stats functions

Random

binornd · bootstrp · datasample · dividerand · exprnd · gamrnd · lhsdesign · normrnd · random · randsample · rng · trnd · unidrnd · unifrnd · wblrnd

Ml

bayesopt · classify · confusionmat · crossvalind · cvpartition · fitclinear · fitctree · fitlm · kmeans · knnsearch · lasso · lassoglm · linkage · lscov · mnrfit · optimizableVariable · pdist · pdist2 · perfcurve · predict · regress · ridge · squareform · test · training · tsne

Summary

binocdf · boxplot · cdf · cdfplot · chi2cdf · corr · corrcoef · corrcov · cov · cov2corr · dummyvar · ecdf · filloutliers · fitdist · geomean · grpstats · harmmean · icdf · isoutlier · kstest · kurtosis · lsline · mad · mode · nanmax · normalize · normcdf · norminv · normpdf · onehotdecode · onehotencode · pdf · prctile · quantile · refline · rmse · skewness · tabulate · tcdf · tiedrank · tinv · tpdf · ttest2 · wblinv

Hist

histc · histcounts · histcounts2

Options

statget · statset

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how mvnrnd is executed, line by line, in Rust.

  • View the source for mvnrnd 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 mvnrnd works
  • Examples
  • Draw five bivariate samples
  • Use one covariance page per mean row
  • Use diagonal variances
  • Draw from a singular covariance
  • Using mvnrnd with coding agents
  • FAQ
  • Related Stats functions
  • Random
  • Ml
  • Summary
  • Hist
  • Options
  • Open-source implementation
  • About RunMat