RunMat
  • Pricing
RunMat
GitHub
GitHub
Sign inTry in browser
DesktopRuntimePhysicsCADAdministrationAgent

Get RunMat updates

New releases, guides and examples.

Product+
  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download
Math+
  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting
Physics+
  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA
Industries+
  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance
Learn+
  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students
Compare+
  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons
Company+
  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms

Product

  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download

Math

  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting

Physics

  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA

Industries

  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance

Learn

  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students

Compare

  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons

Company

  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms
GitHubXLinkedIn

© Dystr, Inc. · RunMat v0.7.1, Nov 17, 2026

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.

/
See all docs
Builtin Reference
    • colon
    • createArray
    • empty
    • eye
    • false
    • full
    • inf
    • int16.empty
    • int32.empty
    • int64.empty
    • int8.empty
    • linspace
    • logspace
    • magic
    • meshgrid
    • nan
    • ndgrid
    • nonzeros
    • ones
    • peaks
    • rand
    • randi
    • randn
    • randperm
    • range
    • sparse
    • spdiags
    • speye
    • spones
    • sprand
    • true
    • uint16.empty
    • uint32.empty
    • uint64.empty
    • uint8.empty
    • zeros

peaks — Generate the standard peaks test surface in MATLAB and RunMat.

peaks(n) evaluates the standard peaks function over an n×n grid spanning [-3, 3] × [-3, 3]:

Z = 3*(1-x)^2 * exp(-x^2 - (y+1)^2)
    - 10*(x/5 - x^3 - y^5) * exp(-x^2 - y^2)
    - 1/3 * exp(-(x+1)^2 - y^2)

It is commonly used to demonstrate 3-D surface plots. Formula and default grid size follow MATLAB semantics.

Syntax

Z = peaks()
Z = peaks(n)
Z = peaks(X, Y)
[X,Y] = peaks(n)
[X,Y,Z] = peaks(n)
[X,Y] = peaks(X, Y)
[X,Y,Z] = peaks(X, Y)

Inputs

n
Type
IntegerScalar
Required
Yes
Default
49
Description
Grid size n for n-by-n sampling.
X
Type
NumericArray
Required
Yes
Description
X coordinate matrix.
Y
Type
NumericArray
Required
Yes
Description
Y coordinate matrix (same size as X).
NameTypeRequiredDefaultDescription
nIntegerScalarYes49Grid size n for n-by-n sampling.
XNumericArrayYes—X coordinate matrix.
YNumericArrayYes—Y coordinate matrix (same size as X).

Returns

Z
Type
NumericArray
Description
Sampled peaks surface values.
X
Type
NumericArray
Description
Grid coordinates along X-axis.
Y
Type
NumericArray
Description
Grid coordinates along Y-axis.
NameTypeDescription
ZNumericArraySampled peaks surface values.
XNumericArrayGrid coordinates along X-axis.
YNumericArrayGrid coordinates along Y-axis.

Returned values from peaks depend on how many outputs the caller requests.

Errors

—
When
More than three outputs are requested.
Message
peaks: too many output arguments; maximum is 3
—
When
The builtin is called with more than two input arguments.
Message
peaks: expected 0, 1, or 2 input arguments
—
When
The n argument is not a numeric scalar.
Message
peaks: n must be a numeric scalar
IdentifierWhenMessage
—More than three outputs are requested.peaks: too many output arguments; maximum is 3
—The builtin is called with more than two input arguments.peaks: expected 0, 1, or 2 input arguments
—The n argument is not a numeric scalar.peaks: n must be a numeric scalar
—The n argument is non-finite.peaks: n must be finite
—The n argument is not an integer.peaks: n must be an integer
—The scalar n argument is not greater than one.peaks: scalar n must be an integer greater than 1
—The n argument exceeds platform limits.peaks: n is too large for this platform
—X/Y inputs are not numeric matrix values.peaks: X and Y must be numeric matrices
—X/Y inputs are not 2-D matrices.peaks: X and Y must be 2-D matrices
—X and Y inputs do not have the same shape.peaks: X and Y must have the same size

Behavior

peaks with no arguments returns a 49×49 matrix (MATLAB default).

peaks(n) requires a scalar integer greater than one and returns an n×n matrix evaluated on an n-point grid from -3 to 3 on both axes. A typed-integer scalar n is a RunMat extension decoded structurally from native storage.

peaks(X, Y) accepts mutually compatible coordinate sizes and returns a broadcast Z matrix.

[X, Y, Z] = peaks(Xm,Ym) returns X and Y equal to the original coordinates, including their exact integer classes and wide values, while Z is computed in the floating peaks formula domain.

When exactly two outputs are requested, [X, Y] = peaks(n) returns only the coordinate grids without Z.

Execution and residency

peaks has both a host implementation and provider paths for supported generated grids and equal-shape resident coordinate inputs. Residency follows the admitted route, not the function name alone.

RunMat may select the active provider automatically for generated grids and equal-shape resident coordinate inputs. Explicit gpuArray coordinate or grid-size input is a separately declared RunMat extension because the public compatibility target does not document GPU-array support.

Examples

Default 49×49 surface

Z = peaks;
surf(Z);

Custom grid size

Z = peaks(30);
surf(Z);
colormap('parula');
colorbar;

Full three-output form

[X, Y, Z] = peaks(40);
surf(X, Y, Z);
shading interp;
colorbar;
view(45, 30);

Caller-supplied coordinate matrices

[X, Y] = meshgrid(linspace(-3, 3, 50), linspace(-3, 3, 50));
Z = peaks(X, Y);
contourf(X, Y, Z);
colorbar;

Combine with contour

[X, Y, Z] = peaks(50);
subplot(1, 2, 1);
surf(X, Y, Z);
view(3);
subplot(1, 2, 2);
contourf(X, Y, Z);
colorbar;

Using peaks with coding agents

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

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

FAQ

Why is the default size 49?⌄

MATLAB chose 49 as the default grid size for peaks. RunMat matches this specification.

Can I get the coordinate grids back as well as Z?⌄

Yes. Use [X, Y, Z] = peaks(n) to retrieve all three matrices.

How do I move the result to the GPU?⌄

RunMat can select the active provider automatically for generated grids. Explicit gpuArray inputs are a declared RunMat extension and are rejected in strict MATLAB compatibility mode.

What values are valid for scalar n?⌄

Scalar n must be an integer greater than one.

Related Array functions

Creation

colon · createArray · empty · eye · false · full · inf · int16.empty · int32.empty · int64.empty · int8.empty · linspace · logspace · magic · meshgrid · nan · ndgrid · nonzeros · ones · rand · randi · randn · randperm · range · sparse · spdiags · speye · spones · sprand · true · uint16.empty · uint32.empty · uint64.empty · uint8.empty · zeros

Accumulation

accumarray

Sorting Sets

argsort · intersect · ismember · ismembertol · issorted · issortedrows · setdiff · setxor · sort · sortrows · union · unique

Shape

blkdiag · cat · circshift · diag · flip · fliplr · flipud · horzcat · ipermute · kron · permute · repelem · repmat · reshape · rot90 · shiftdim · squeeze · toeplitz · tril · triu · vertcat

Combinatorics

combinations · nchoosek · perms

Binning

discretize

Indexing

find · ind2sub · sub2ind

Grouping

findgroups · groupcounts · grp2idx · splitapply

Introspection

height · iscolumn · isempty · ismatrix · isrow · isscalar · isvector · length · ndims · numel · size · width

Source you can read

Every RunMat function's source is public. Read exactly how peaks is executed, line by line, in Rust.

  • View the source for peaks 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.

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
  • Behavior
  • Execution and residency
  • Examples
  • Default 49×49 surface
  • Custom grid size
  • Full three-output form
  • Caller-supplied coordinate matrices
  • Combine with contour
  • Using peaks with coding agents
  • FAQ
  • Related Array functions
  • Creation
  • Accumulation
  • Sorting Sets
  • Shape
  • Combinatorics
  • Binning
  • Indexing
  • Grouping
  • Introspection
  • Source you can read
  • About RunMat