View all functions

CategoryMath: Poly

What does the polyint function do in MATLAB / RunMat?

polyint(p) returns the polynomial that integrates the coefficient vector p once, appending the constant of integration at the end of the coefficient list. Coefficients follow MATLAB's descending power convention: p(1) multiplies the highest power of x, and p(end) is the constant term.

How does the polyint function behave in MATLAB / RunMat?

  • 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 constant k yields [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.

polyint Function GPU Execution Behaviour

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.

Examples of using the polyint function in MATLAB / RunMat

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
         0

Integrating the zero polynomial

q = polyint([]);

Expected output:

q = 0;

Integrating 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 behavior:

result = [0.3333  -2  6  0];

GPU residency in RunMat (Do I need gpuArray?)

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.

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.

See Also

polyder, polyval, polyfit, gpuArray, gather