What does the polyder function do in MATLAB / RunMat?
polyder differentiates polynomials represented by their coefficient vectors. The coefficients
follow MATLAB’s convention: the first element corresponds to the highest power of x. The builtin
supports three related operations:
polyder(p)returns the derivative of a polynomialp.polyder(p, a)applies the product rule to the convolutionconv(p, a).[num, den] = polyder(u, v)returns the derivative of a rational functionu(x) / v(x)using the quotient rule, yielding the numeratornumand denominatorden.
How does the polyder 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 differentiation.
- Leading zeros are removed in outputs (unless the polynomial is identically zero, in which case a single zero coefficient is returned).
- The orientation of the first input polynomial is preserved for the derivative of a single
polynomial or a product; the denominator in the quotient rule preserves the orientation of
v. - Calling
polyder(p, a)with a single output applies the product rule. Capturing two outputs alongside two input polynomials returns the quotient-rule numerator and denominator (u' * v - u * v',v * v). - Empty inputs are treated as the zero polynomial.
- When inputs live on the GPU (e.g.,
gpuArray) and the active provider exposes the polyder hooks, differentiation runs entirely on-device and returns trimmed GPU tensors. Providers that lack the hooks fall back to gathering coefficients to the host, executing the reference CPU implementation, and returning host-resident results. Explicit calls togpuArrayremain available if you need to force residency.
polyder Function GPU Execution Behaviour
When a provider advertises the polyder hooks (the in-process and WGPU backends both do), single
polynomials and the product/quotient forms execute fully on the GPU. Outputs preserve the
orientation of the leading input while trimming leading zeros exactly as the CPU path does. If the
provider declines the request—because the coefficients are complex or the backend lacks support—
RunMat automatically gathers the inputs and falls back to the CPU reference implementation to
preserve MATLAB compatibility.
Examples of using the polyder function in MATLAB / RunMat
Differentiating a cubic polynomial
p = [3 -2 5 7]; % 3x^3 - 2x^2 + 5x + 7
dp = polyder(p);
Expected output:
dp = [9 -4 5];
Applying the product rule
p = [1 0 -2]; % x^2 - 2
a = [1 1]; % x + 1
dp = polyder(p, a); % derivative of conv(p, a)
Expected output:
dp = [3 2 -2];
Differentiating a rational function
u = [1 0 -4]; % x^2 - 4
v = [1 -1]; % x - 1
[num, den] = polyder(u, v); % derivative of (u / v)
Expected output:
num = [1 -2 4];
den = [1 -2 1];
Preserving column-vector orientation
p = [1; 0; -3]; % column vector coefficients
dp = polyder(p);
Expected output:
dp =
2
0
Differentiating complex-valued coefficients
p = [1+2i, -3, 4i];
dp = polyder(p);
Expected output:
dp = [2+4i, -3];
Working with gpuArray inputs
g = gpuArray([2 0 -5 4]);
dp = polyder(g); % stays on the GPU when provider hooks are available
result = gather(dp);
Expected behaviour:
result = [6 0 -5];
FAQ
What happens if I pass an empty coefficient vector?
The empty vector represents the zero polynomial. polyder([]) returns [0], and the product and
quotient forms treat empty inputs as zeros.
Does polyder support column-vector coefficients?
Yes. The orientation of the first polynomial is preserved for single-polynomial and product
derivatives. For the quotient rule, the numerator inherits the orientation of u and the
denominator inherits the orientation of v.
How are leading zeros handled in the result?
Leading zeros are removed automatically to mirror MATLAB. If all coefficients cancel out, a single zero coefficient is returned.
Can I differentiate logical or integer coefficient vectors?
Yes. Logical and integer inputs are promoted to double precision before differentiation, matching MATLAB semantics.
How do I compute the derivative of a rational function?
Call [num, den] = polyder(u, v). The numerator and denominator are the coefficients of
(u' * v - u * v') and v * v, respectively, with leading zeros removed.
Does the builtin launch GPU kernels?
Yes whenever the active acceleration provider implements the polyder hooks. The in-process and
WGPU backends both execute the derivative on the device. Providers that lack the hooks—or inputs that
require complex arithmetic—fall back to the CPU reference implementation, returning the result on the
host. Wrap the output in gpuArray manually if you need to restore device residency in that case.
What if I request more than two outputs?
polyder only defines one or two outputs. Additional requested outputs are filled with 0, just as
RunMat currently does for other MATLAB builtins whose extra outputs are ignored.
Are complex coefficients supported in the quotient rule?
Yes. Both the numerator and denominator are computed using full complex arithmetic, so mixed real/complex inputs work without additional steps.
Do I need to normalise or pad my coefficient vectors?
No. Provide coefficients exactly as MATLAB expects (highest power first). The builtin takes care of padding, trimming, and orientation.
How precise is the computation?
All arithmetic uses IEEE 754 double precision (f64), matching MATLAB’s default numeric type.