RunMat
GitHub

deconv — Divide one polynomial (or 1-D sequence) by another, returning the quotient and remainder.

deconv(b, a) performs one-dimensional polynomial long division. Given coefficient vectors b and a, it returns a quotient q and remainder r such that

conv(a, q) + r == b

Coefficients follow MATLAB conventions: the first entry stores the highest-order term and the last entry stores the constant term. Both real and complex inputs are supported.

How deconv works in RunMat

  • Inputs must be scalars, row vectors, or column vectors. Multi-dimensional tensors are rejected.
  • Leading zeros are ignored during division, matching MATLAB’s behaviour. The outputs include just enough coefficients to represent the resulting polynomials (with at least one element for the zero polynomial).
  • When length(b) < length(a), the quotient is zero and the remainder equals b.
  • Logical inputs are promoted to double precision prior to division (TRUE → 1.0, FALSE → 0.0).
  • Complex coefficients are handled exactly; the quotient and remainder retain complex values.
  • Empty denominators and all-zero denominators raise MATLAB-compatible errors.

How deconv runs on the GPU

When either input resides on the GPU (gpuArray values), RunMat first checks whether the active acceleration provider exposes a dedicated deconvolution hook. The current providers (in-process and WGPU) do not yet offer this kernel, so the runtime always:

1. Gathers the device operands into host memory. 2. Performs the polynomial long division on the CPU. 3. Re-uploads real-valued results to the provider so downstream fused kernels can remain device-resident (complex outputs stay on the host until providers add complex buffer uploads).

This fallback keeps behaviour identical to MATLAB. Gather the outputs explicitly only when you need them on the host.

Examples

Recovering a factor from a polynomial product

p = conv([1 2], [1 -3 2]);   % Multiply two polynomials
[q, r] = deconv(p, [1 2])   % Divide by the first factor

Expected output:

q = [1 -3 2];
r = 0

Obtaining a non-zero remainder

[q, r] = deconv([1 4 7], [1 2])

Expected output:

q = [1 2];
r = [3]

Dividing by a longer sequence

[q, r] = deconv([3 5], [1 0 2])

Expected output:

q = 0;
r = [3 5]

Handling leading zeros explicitly

b = [0 0 1 2];
a = [0 1 1];
[q, r] = deconv(b, a)

Expected output:

q = [1];
r = [1]

Complex polynomial division

b = [1+2i 3-4i 2];
a = [1-i 2+i];
[q, r] = deconv(b, a)

Expected output:

q = [-0.5+1.5i 6-0.5i];
r = [-10.5-5i]

GPU inputs with automatic host fallback

b = gpuArray([1 3 3 1]);
a = gpuArray([1 1]);
[q, r] = deconv(b, a); % Quotient stays on the GPU when possible
r = gather(r);         % Explicitly gather the remainder if needed on the host

FAQ

What happens if the denominator is empty or entirely zero?

An error is raised. MATLAB requires a non-empty, non-zero denominator polynomial.

Can I pass logical or integer vectors?

Yes. They are promoted to double precision before division so the results match MATLAB exactly.

Why are leading zeros dropped from the outputs?

They do not change the represented polynomial. Dropping them keeps results compact and mirrors MATLAB’s behaviour. The zero polynomial is returned as a single zero.

Does deconv support column vectors?

Absolutely. The orientation of the numerator (b) determines the orientation of both the quotient and remainder.

How should I reconstruct the original polynomial?

conv(a, q) + r (using MATLAB’s polynomial addition rules, which pad shorter vectors on the left) recreates the original numerator.

Are FFT-based deconvolutions supported?

deconv implements exact polynomial long division. For FFT-based signal deconvolution, combine fft, elementwise division, and ifft manually.

What about numerical stability?

deconv mirrors MATLAB’s long-division semantics. For ill-conditioned problems, consider scaling the coefficients or using higher precision (e.g., symbolic toolboxes) just as you would in MATLAB.

Can I request both outputs in one statement?

Yes. [q, r] = deconv(b, a) returns both quotient and remainder; requesting only one output returns the quotient.

These functions work well alongside deconv. Each page has runnable examples you can try in the browser.

conv, conv2, fft, ifft, gpuArray, gather, filter

Open-source implementation

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

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code — faster, on any GPU, with no license required.

  • Simulations that took hours now take minutes. RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed.
  • Start running code in seconds. Open the browser sandbox or download a single binary. No license server, no IT ticket, no setup.
  • A full development environment. GPU-accelerated 2D and 3D plotting, automatic versioning on every save, and a browser IDE you can share with a link.

Getting started · Benchmarks · Pricing

Try RunMat — free, no sign-up

Start running MATLAB code immediately in your browser.