f(x)

Polynomials

Your Progress in this Chapter

0%

0 / 12 units completed

Chapter Overview

Polynomial Arithmetics

Section 2.4 of 614 min6 code examples

Polynomial Arithmetic

In SepalSolver, polynomials are not just static formulas; they are dynamic objects that can be added, subtracted, multiplied, and divided. By representing polynomials as an array of doubles in descending order, we can leverage classical signal processing algorithms, such as convolution, to perform these operations with high numerical efficiency.

1. Addition and Subtraction (PolyAdd / PolySub)

Adding or subtracting polynomials involves summing the coefficients of corresponding powers. Since our arrays are in descending order, we must carefully align the "tails" of the arrays (the constant terms) before performing the operation, especially if the polynomials have different degrees.

Example 1C#

1
2
3
4
5
6
7
8
9
10
Code is ready to run
OutputFrom the book
Sum:
 = [1, 6, 8]
Diff:
 = [1, -2, -2]

2. Multiplication (Conv)

Multiplying two polynomials is mathematically equivalent to the convolution of their coefficient arrays. If you multiply a polynomial of degree N by one of degree M, the resulting degree will be N + M. We use a sliding-window approach to compute each term of the resulting array.

Example 2C#

1
2
3
4
5
6
Code is ready to run
OutputFrom the book
Product:
 = [1, 0, -1]

3. Division and Remainder (Deconv)

Polynomial division is implemented via deconvolution (synthetic division). Dividing P_1 by P_2 yields two results: the Quotient (Q) and the Remainder (R). This is vital for operations like partial fraction expansion or checking for factorability.

Example 3C#

1
2
3
4
5
6
7
8
Code is ready to run
OutputFrom the book
Quotient:
 = [1, -1]
Remainder:
 = [0, 0, 0]

Examples

.. Admonition:: Example 1 : Combining Structural Models

Suppose you are combining two transfer functions in a control system. You need to add the characteristic polynomials of two sub-components. Using PolyAdd, the solver automatically handles the degree mismatch between a quadratic and a linear system.

Example 4C#

1
2
3
4
5
6
7
Code is ready to run
OutputFrom the book
New Degree: 2
Combined Coefficients: [1, -4, 8]

.. Admonition:: Example 2 : Expanding a Product of Factors

In root-finding verification, you might want to multiply factors (x - r_1)(x - r_2) to see if you recover the original polynomial. Conv makes this/// expansion trivial and numerically stable.

Example 5C#

1
2
3
4
5
6
Code is ready to run
OutputFrom the book
Expanded = [1, -5, 6]

.. Admonition:: Example 3 : Finding Remainders in Signal Filtering

When dividing polynomials to check for divisibility or performing long division in a filter design, the remainder tells us if one polynomial is a perfect factor of another.

Example 6C#

1
2
3
4
5
Code is ready to run
OutputFrom the book
Remainder is zero? False

Numerical Note: Array Sizing

During PolyAdd and PolySub, SepalSolver creates a result array equal to the size of the largest input. During Conv, the result size is always p1.Length + p2.Length - 1. Understanding these allocation rules helps in managing memory when performing recursive polynomial arithmetic.