polyint — Integrate polynomial coefficient vectors in MATLAB and RunMat.
polyint(p) integrates polynomial coefficient vector p once and appends a constant of integration term. Coefficient ordering and optional constant handling follow MATLAB semantics.
Syntax
q = polyint(p)
q = polyint(p, k)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
p | Any | Yes | — | Polynomial coefficient vector. |
k | Any | No | — | Constant of integration. |
Returns
| Name | Type | Description |
|---|---|---|
q | Any | Integrated polynomial coefficient vector. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:polyint:InvalidArgument | Input arity or integration-constant argument is malformed. | polyint: invalid argument |
RunMat:polyint:InvalidInput | Input polynomial cannot be interpreted as a numeric coefficient vector. | polyint: invalid input |
RunMat:polyint:Internal | Runtime fails while building output tensors or provider fallback paths. | polyint: internal runtime failure |
How polyint works
- Accepts real or complex scalars, row vectors, column vectors, or empty vectors. Inputs with more than one non-singleton dimension raise MATLAB-compatible errors.
- Logical and integer coefficients are promoted to double precision before integration.
- The optional second argument supplies the constant of integration. It must be a scalar (real or complex). When omitted, the constant defaults to
0. - Leading zeros are preserved. Integrating
[0 0 5]produces[0 0 5 0], matching MATLAB. - Empty inputs integrate to the constant of integration (default
0). Specifying a constantkyields[k]. - The orientation of the input vector is preserved: row vectors stay row vectors, column vectors stay column vectors, and scalars return a row vector.
- When coefficients reside on the GPU, RunMat gathers them to the host, performs the integration, and re-uploads real-valued results so downstream kernels retain residency.
Does RunMat run polyint on the GPU?
When a GPU provider is registered and the coefficient vector is real-valued, RunMat calls the provider's dedicated polyint kernel. The input stays on the device, the kernel divides each coefficient by the appropriate power, and the supplied constant of integration is written directly into device memory. If the coefficients or the constant are complex, or if the provider reports that the hook is unavailable, the runtime gathers data back to the host, performs the integration in double precision, and re-uploads the result when it is purely real.
GPU memory and residency
You usually do not need to call gpuArray just for polyint. When inputs already live on the GPU and a provider is active, RunMat keeps the data on the device and executes the integration there for real-valued coefficients. For complex inputs, or when no provider hook is available, the runtime falls back to the host implementation transparently.
Examples
Integrating a cubic polynomial
p = [3 -2 5 7]; % 3x^3 - 2x^2 + 5x + 7
q = polyint(p)Expected output:
q = [0.75 -0.6667 2.5 7 0]Supplying a constant of integration
p = [4 0 -8];
q = polyint(p, 3)Expected output:
q = [1.3333 0 -8 3]Preserving column-vector orientation
p = [2; 0; -6];
q = polyint(p)Expected output:
q =
0.6667
0
-6.0000
0Integrating the zero polynomial
q = polyint([])Expected output:
q = 0Integrating complex coefficients
p = [1+2i -3 4i];
q = polyint(p, -1i)Expected output:
q = [(1+2i)/3 -1.5 4i -1i]Working with gpuArray inputs
g = gpuArray([1 -4 6]);
q = polyint(g); % Gathered to host, integrated, and re-uploaded
result = gather(q)Expected output:
result = [0.3333 -2 6 0]Using polyint with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how polyint changes the result.
Run a small polyint example, explain the result, then change one input and compare the output.
FAQ
Does polyint change the orientation of my coefficients?⌄
No. Row vectors stay row vectors, column vectors stay column vectors, and scalars return a row vector with two elements after integration.
What happens when I pass an empty vector?⌄
An empty vector represents the zero polynomial. polyint([]) returns the constant of integration, so the default result is 0 and polyint([], k) returns k.
Can the constant of integration be complex?⌄
Yes. Provide any scalar numeric value (real or complex). The constant is appended to the integrated polynomial exactly as MATLAB does.
Are logical or integer coefficients supported?⌄
Yes. They are promoted to double precision before integration, ensuring identical behaviour to MATLAB.
Will the result stay on the GPU?⌄
Real-valued outputs are re-uploaded to the GPU when a provider is available. Complex outputs remain on the host because current providers do not expose complex tensor handles.
How precise is the computation?⌄
All arithmetic uses IEEE 754 double precision (f64), mirroring MATLAB's default numeric type.
Related Math functions
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
Structure
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how polyint is executed, line by line, in Rust.
- View the source for polyint 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.