RunMat
GitHub

integral — Approximate finite scalar definite integrals in MATLAB and RunMat.

q = integral(fun, a, b) approximates the definite integral of fun from a to b using adaptive quadrature. Current support targets scalar-valued integrands over finite real bounds, following MATLAB-style call semantics.

Syntax

q = integral(fun, xmin, xmax)
q = integral(fun, xmin, xmax, options)
q = integral(fun, xmin, xmax, name, value, ...)

Inputs

NameTypeRequiredDefaultDescription
funAnyYesScalar integrand callback.
xminAnyYesLower integration bound.
xmaxAnyYesUpper integration bound.
optionsAnyNoOptions struct for AbsTol/RelTol/MaxFunEvals.
namePropertyNameNoOption name.
valuePropertyValueVariadicOption value and additional name/value pairs.

Returns

NameTypeDescription
qNumericScalarNumerical integral estimate.

Errors

IdentifierWhenMessage
RunMat:integral:InvalidArgumentOption grammar/name-value parsing is invalid.integral: invalid argument
RunMat:integral:InvalidInputBounds/integrand/adaptive solver semantics are invalid.integral: invalid input

How integral works

  • The function may be a named function handle such as @sin, an anonymous function such as @(x) x.^2, or a function-handle string.
  • The integration loop evaluates the integrand at scalar sample points and adapts subintervals using Simpson error estimates.
  • The integrand must return a finite real scalar. Array-valued and complex-valued integrands are not supported yet.
  • Finite reversed bounds are accepted and negate the result. Equal bounds return zero.
  • AbsTol, RelTol, and MaxFunEvals name/value options are accepted for the initial scalar implementation.

Examples

Integrate a polynomial anonymous function

q = integral(@(x) x.^2, 0, 1)

Expected output:

q =
    0.3333

Integrate sine over one half-period

q = integral(@sin, 0, pi)

Expected output:

q =
    2.0000

Set tighter tolerances

q = integral(@sin, 0, pi, 'AbsTol', 1e-12, 'RelTol', 1e-8)

Expected output:

q =
    2.0000

Using integral with coding agents

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

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

FAQ

Is this the same as trapz?

No. integral evaluates a function handle adaptively over continuous bounds. trapz integrates already-sampled discrete data.

Does integral support vector-valued functions?

Not yet. The initial implementation supports finite real scalar-valued integrands.

Does integral run on the GPU?

The adaptive solver runs on the host because it repeatedly invokes user code through function-handle dispatch. The callback itself may call GPU-aware builtins.

Elementwise

abs · angle · complex · conj · double · exp · expm1 · factorial · gamma · hypot · imag · ldivide · log · log10 · log1p · log2 · minus · nextpow2 · plus · pow2 · power · rdivide · real · sign · single · sqrt · times

Trigonometry

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

Reduction

all · any · cummax · cummin · cumprod · cumsum · cumtrapz · diff · gradient · max · mean · median · min · nnz · prod · std · sum · trapz · var

Signal

blackman · butter · conv · conv2 · deconv · filter · hamming · hann · sawtooth · sinc · square

Rounding

ceil · fix · floor · mod · rem · round

Factor

chol · eig · lu · qr · svd

Solve

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

Fft

fft · fft2 · fftshift · ifft · ifft2 · ifftshift

Interpolation

interp1 · interp2 · pchip · ppval · spline

Ode

ode15s · ode23 · ode45

Open-source implementation

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

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.