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

Run math blazing fast

GitHubX (Twitter)LinkedIn

Company

  • About
  • Pricing
  • Contact
  • License
  • Privacy

Learn

  • Docs
  • Blog
  • Benchmarks
  • RunMat vs MATLAB Online

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.

/
See all docs
Builtin Reference
    • all
    • any
    • bounds
    • cummax
    • cummin
    • cumprod
    • cumsum
    • cumtrapz
    • diff
    • gradient
    • max
    • maxk
    • mean
    • median
    • min
    • mink
    • movmax
    • movmean
    • movmedian
    • movmin
    • movprod
    • movstd
    • movsum
    • movvar
    • nnz
    • prod
    • rms
    • std
    • sum
    • trapz
    • var

cumtrapz — Compute cumulative trapezoidal integration in MATLAB and RunMat.

cumtrapz(Y) computes cumulative trapezoidal integrals of sampled data in Y. The output matches Y in size, with zero at the first element of the integration dimension and running integral values thereafter.

Syntax

Q = cumtrapz(Y)
Q = cumtrapz(Y, dim)
Q = cumtrapz(X, Y)
Q = cumtrapz(X, Y, dim)

Inputs

NameTypeRequiredDefaultDescription
YAnyYes—Sample values.
dimAnyYes—Integration dimension.
XAnyYes—Sample points or spacing.

Returns

NameTypeDescription
QNumericArrayCumulative trapezoidal integral output.

Errors

IdentifierWhenMessage
RunMat:cumtrapz:InvalidArgumentInput argument count, dimension selector, or spacing arguments are invalid.cumtrapz: invalid argument
RunMat:cumtrapz:InvalidInputInput values cannot be converted to supported numeric integration domains.cumtrapz: invalid input
RunMat:cumtrapz:InternalIntegration execution fails during gather, allocation, or provider promotion.cumtrapz: internal integration failure

How cumtrapz works

  • cumtrapz(Y) assumes unit spacing between adjacent samples.
  • cumtrapz(X, Y) accepts documented single- or double-precision scalar spacing or a coordinate vector whose length matches the working dimension. A same-size coordinate tensor is an explicitly gated RunMat extension.
  • cumtrapz(..., dim) selects the working dimension explicitly. Dimensions larger than ndims(Y) behave like singleton axes, so the result stays zero along those slices.
  • Documented Y classes are single and double, real or complex, and output preserves single versus double. Typed-integer and logical Y, typed-integer or logical X, and typed-integer dim are separate RunMat-only extensions.
  • Typed-integer Y and X cross the binary64 integration boundary only when every authoritative integer value is exactly representable; otherwise RunMat reports an error instead of silently rounding.
  • When the selected dimension has length 0 or 1, the output is zero along that dimension because there are no intervals to accumulate.

Does RunMat run cumtrapz on the GPU?

Floating real and complex-interleaved resident Y can use provider-backed cumulative trapezoidal integration with real unit, scalar, coordinate-vector, or gated same-size coordinate-tensor spacing.

Mixed-provider spacing does not cross-dispatch. Integer or logical resident values, missing hooks, provider errors, and contract-invalid results use the exactness-checked host fallback path.

GPU memory and residency

Resident floating input dispatch is resolved from the input handle's owner, not the ambient active provider. Native results are validated for shape, storage, precision, device, and owner; invalid native results are freed before host fallback. Fallback returns to the first resident owner when provider precision permits.

Examples

Computing a cumulative integral with explicit coordinates

x = [0 1 3];
y = [0 1 2];
q = cumtrapz(x, y)

Expected output:

q = [0 0.5 3.5]

Using unit spacing for sampled data

y = [1 2 3];
q = cumtrapz(y)

Expected output:

q = [0 1.5 4]

Accumulating across rows in a matrix

A = [1 2 3; 4 5 6];
q = cumtrapz(A, 2)

Expected output:

q =
     0    1.5    4
     0    4.5   10

Running cumtrapz on GPU data

G = gpuArray([1 2 3]);
q = cumtrapz(G);
result = gather(q)

Expected output:

result = [0 1.5 4]

Using cumtrapz with coding agents

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

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

FAQ

How is cumtrapz different from trapz?⌄

trapz returns the final integrated value, while cumtrapz returns the running integral at every sample.

Why is the first element zero?⌄

There is no interval before the first sample, so the cumulative integral begins at zero.

What forms of X are accepted?⌄

The compatibility surface is a single- or double-precision scalar spacing or coordinate vector matching the integration dimension. RunMat mode additionally admits same-size coordinate tensors behind the cumtrapz-tensor-spacing extension gate.

Does cumtrapz support complex inputs?⌄

Yes. RunMat accumulates the real and imaginary components independently and returns a complex result.

Does cumtrapz keep gpuArray residency?⌄

Yes for documented floating real or complex samples when the owning provider accepts and returns the required shape, storage, precision, device, and ownership contract. Other admitted RunMat forms fall back through host computation and are restored to the first resident owner when possible.

Related Math functions

Reduction

all · any · bounds · cummax · cummin · cumprod · cumsum · diff · gradient · max · maxk · mean · median · min · mink · movmax · movmean · movmedian · movmin · movprod · movstd · movsum · movvar · nnz · prod · rms · std · sum · trapz · var

Elementwise

abs · angle · bsxfun · complex · conj · double · erf · erfcinv · exp · expm1 · factorial · flintmax · gamma · gammaln · heaviside · hypot · idivide · imag · intmax · intmin · ldivide · log · log10 · log1p · log2 · minus · nextpow2 · plus · pow2 · power · rdivide · real · realmax · realmin · realsqrt · rescale · sign · single · sqrt · swapbytes · times · typecast · uint16 · uint32 · uint8

Trigonometry

acos · acosh · asin · asinh · atan · atan2 · atanh · cos · cosd · cosh · cospi · deg2rad · pol2cart · rad2deg · sin · sind · sinh · sinpi · tan · tand · tanh

Structure

bandwidth · isdiag · ishermitian · issymmetric · istril · istriu · symrcm

Signal

blackman · butter · buttord · cheb2ord · conv · conv2 · deconv · downsample · envelope · filter · filtfilt · fir1 · freqz · gauspuls · hamming · hann · hilbert · periodogram · pulstran · pwelch · rectpuls · resample · sawtooth · sinc · spectrogram · square · tripuls · unwrap · upsample · zplane

Rounding

ceil · fix · floor · mod · rem · round

Factor

chol · decomposition · eig · eigs · lu · qr · svd

Solve

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

Optim

coneprog · fminbnd · fminunc · fsolve · fzero · integral · linprog · lsqcurvefit · lsqnonlin · optimoptions · optimset · quad · secondordercone

Ops

cross · ctranspose · dot · mldivide · mpower · mrdivide · mtimes · pagemtimes · pagetranspose · trace · transpose

Symbolic

digits · int · limit · piecewise · sym · syms · vpa

Fft

fft · fft2 · fftn · fftshift · ifft · ifft2 · ifftn · ifftshift

Interpolation

griddedInterpolant · interp1 · interp1q · interp2 · pchip · ppval · spline

Discrete

lcm · primes

Ode

ode15s · ode23 · ode45

Poly

polyder · polyfit · polyint · polyval · roots

Open-source implementation

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

  • View the source for cumtrapz 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 cumtrapz works
  • Does RunMat run cumtrapz on the GPU?
  • GPU memory and residency
  • Examples
  • Computing a cumulative integral with explicit coordinates
  • Using unit spacing for sampled data
  • Accumulating across rows in a matrix
  • Running cumtrapz on GPU data
  • Using cumtrapz with coding agents
  • FAQ
  • Related Math functions
  • Reduction
  • Elementwise
  • Trigonometry
  • Structure
  • Signal
  • Rounding
  • Factor
  • Solve
  • Optim
  • Ops
  • Symbolic
  • Fft
  • Interpolation
  • Discrete
  • Ode
  • Poly
  • Open-source implementation
  • About RunMat