Robot Control Library
Polynomial

Description

Functions for polynomial manipulation.

<rc/math/polynomial.h>

We represent polynomials as a vector of coefficients with the highest power term on the left at vector index 0. The following polynomial manipulation functions are designed to behave like their counterparts in the Numerical Renaissance codebase.

Author
James Strawson
Date
2016

Functions

int rc_poly_print (rc_vector_t v)
 Prints a polynomial in human-readable format in one line. More...
 
int rc_poly_conv (rc_vector_t a, rc_vector_t b, rc_vector_t *c)
 Convolutes the polynomials a&b and places the result in vector c. More...
 
int rc_poly_power (rc_vector_t a, int n, rc_vector_t *b)
 Raises a polynomial a to itself n times where n is greater than or equal to 0. More...
 
int rc_poly_add (rc_vector_t a, rc_vector_t b, rc_vector_t *c)
 Add two polynomials a&b with right justification and place the result in c. More...
 
int rc_poly_add_inplace (rc_vector_t *a, rc_vector_t b)
 Adds polynomials a&b with right justification. More...
 
int rc_poly_subtract (rc_vector_t a, rc_vector_t b, rc_vector_t *c)
 Subtracts two polynomials a-b with right justification and places the result in c. More...
 
int rc_poly_subtract_inplace (rc_vector_t *a, rc_vector_t b)
 Subtracts b from a with right justification. More...
 
int rc_poly_differentiate (rc_vector_t a, int d, rc_vector_t *b)
 Calculates the dth derivative of the polynomial a and places the result in vector b. More...
 
int rc_poly_divide (rc_vector_t n, rc_vector_t d, rc_vector_t *div, rc_vector_t *rem)
 Divides denominator d into numerator n. The remainder is placed into vector rem and the divisor is placed into vector div. More...
 
int rc_poly_butter (int N, double wc, rc_vector_t *b)
 Calculates coefficients for continuous-time Butterworth polynomial of order N and cutoff wc (rad/s) and places them in vector b. More...
 

Function Documentation

◆ rc_poly_print()

int rc_poly_print ( rc_vector_t  v)

Prints a polynomial in human-readable format in one line.

Like rc_print_vector, but assumes the contents represent a polynomial and prints the coefficients with trailing powers of x for easier reading. This relies on your terminal supporting unicode UTF-8. numer of coefficients and there the length of vector v must be less than or equal to 10.

Parameters
[in]vpolynomial coefficients to be printed
Returns
0 on success or -1 on failure
Examples:
rc_test_polynomial.c.

◆ rc_poly_conv()

int rc_poly_conv ( rc_vector_t  a,
rc_vector_t  b,
rc_vector_t c 
)

Convolutes the polynomials a&b and places the result in vector c.

This finds the coefficients of the polynomials resulting from multiply a*b. The original contents of c are freed and new memory is allocated if necessary.

Parameters
[in]aFirst set of coefficients
[in]bSecond set of coefficients
[out]cVector to output resulting coefficients
Returns
Returns 0 on success or -1 on failure.
Examples:
rc_test_polynomial.c.

◆ rc_poly_power()

int rc_poly_power ( rc_vector_t  a,
int  n,
rc_vector_t b 
)

Raises a polynomial a to itself n times where n is greater than or equal to 0.

Places the result in vector b, any existing memory allocated for b is freed and its contents are lost. Returns 0 on success and -1 on failure.

Parameters
[in]aInitial coefficients
[in]nPower, must be >=0
[out]bresulting coefficients
Returns
Returns 0 on success or -1 on failure.
Examples:
rc_test_polynomial.c.

◆ rc_poly_add()

int rc_poly_add ( rc_vector_t  a,
rc_vector_t  b,
rc_vector_t c 
)

Add two polynomials a&b with right justification and place the result in c.

Any existing memory allocated for c is freed and its contents are lost.

Parameters
[in]aFirst input
[in]bsecond input
[out]coutput
Returns
Returns 0 on success and -1 on failure.
Examples:
rc_test_polynomial.c.

◆ rc_poly_add_inplace()

int rc_poly_add_inplace ( rc_vector_t a,
rc_vector_t  b 
)

Adds polynomials a&b with right justification.

The result is placed in vector a and a's original contents are lost. More memory is allocated for a if necessary.

Parameters
aFirst input and where output is written
[in]bsecond input
Returns
Returns 0 on success and -1 on failure.
Examples:
rc_test_polynomial.c.

◆ rc_poly_subtract()

int rc_poly_subtract ( rc_vector_t  a,
rc_vector_t  b,
rc_vector_t c 
)

Subtracts two polynomials a-b with right justification and places the result in c.

Any existing memory allocated for c is freed and its contents are lost. Returns 0 on success and -1 on failure.

Parameters
[in]aFirst input
[in]bsecond input
[out]coutput
Returns
Returns 0 on success and -1 on failure.
Examples:
rc_test_polynomial.c.

◆ rc_poly_subtract_inplace()

int rc_poly_subtract_inplace ( rc_vector_t a,
rc_vector_t  b 
)

Subtracts b from a with right justification.

a stays in place and new memory is allocated only if b is longer than a.

Parameters
aFirst input and where output is written
[in]bsecond input
Returns
Returns 0 on success and -1 on failure.
Examples:
rc_test_polynomial.c.

◆ rc_poly_differentiate()

int rc_poly_differentiate ( rc_vector_t  a,
int  d,
rc_vector_t b 
)

Calculates the dth derivative of the polynomial a and places the result in vector b.

Parameters
[in]aInput polynomial coefficients
[in]dwhich derivative to take (>=0)
[out]bresult
Returns
Returns 0 on success and -1 on failure.
Examples:
rc_test_polynomial.c.

◆ rc_poly_divide()

int rc_poly_divide ( rc_vector_t  n,
rc_vector_t  d,
rc_vector_t div,
rc_vector_t rem 
)

Divides denominator d into numerator n. The remainder is placed into vector rem and the divisor is placed into vector div.

Parameters
[in]nnumerator
[in]ddenominator
divThe resulting divisor
remThe resulting remainder
Returns
Returns 0 on success and -1 on failure.
Examples:
rc_test_polynomial.c.

◆ rc_poly_butter()

int rc_poly_butter ( int  N,
double  wc,
rc_vector_t b 
)

Calculates coefficients for continuous-time Butterworth polynomial of order N and cutoff wc (rad/s) and places them in vector b.

Parameters
[in]NOrder of the polynomial
[in]wccutoff frequency in rad/s
[out]bresulting coefficients
Returns
Returns 0 on success and -1 on failure.
Examples:
rc_test_polynomial.c.