Rational Function
RationalFunction(terms, poly=None, atol=None, rtol=None, ztol=None)
Rational function represented by sum of terms with a single pole for the proper part, plus a residual polynomial for the improper part.
The rational function, given a polynomial \(p(x)\) and a list of terms with roots \(r_i\), coefficients \(c_i\) and order \(k_i\), is defined as:
according to the tolerances passed to the constructor or the global approximation options (see set_approximation_options).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
terms
|
list[RationalTerm]
|
List of terms. |
required |
poly
|
Polynomial
|
Residual polynomial. Defaults to None. |
None
|
atol
|
float
|
Absolute tolerance for root equivalence. Defaults to None. |
None
|
rtol
|
float
|
Relative tolerance for root equivalence. Defaults to None. |
None
|
ztol
|
float
|
Absolute tolerance below which imaginary or real part of roots will be approximated to zero. Defaults to None. |
None
|
Source code in src/rational_functions/ratfunc.py
poles
property
Get the poles of the rational function.
Returns:
Type | Description |
---|---|
list[PolynomialRoot]
|
list[PolynomialRoot]: List of poles. |
numerator
cached
property
Get the numerator polynomial of the rational function.
Returns:
Name | Type | Description |
---|---|---|
Polynomial |
Polynomial
|
Numerator polynomial. |
denominator
cached
property
Get the denominator polynomial of the rational function.
Returns:
Name | Type | Description |
---|---|---|
Polynomial |
Polynomial
|
Denominator polynomial. |
__neg__()
Negate the rational function.
Returns:
Name | Type | Description |
---|---|---|
RationalFunction |
RationalFunction
|
Negated rational function. |
Source code in src/rational_functions/ratfunc.py
__add__(other)
Add two rational functions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
RationalFunction
|
Other rational function to add. |
required |
Returns:
Name | Type | Description |
---|---|---|
RationalFunction |
RationalFunction
|
Resulting rational function. |
Source code in src/rational_functions/ratfunc.py
__radd__(other)
Right add operator for RationalFunction.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
RationalFunction
|
Other rational function to add. |
required |
Returns:
Name | Type | Description |
---|---|---|
RationalFunction |
RationalFunction
|
Resulting rational function. |
Source code in src/rational_functions/ratfunc.py
__sub__(other)
Subtract two rational functions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
RationalFunction
|
Other rational function to subtract. |
required |
Returns:
Name | Type | Description |
---|---|---|
RationalFunction |
RationalFunction
|
Resulting rational function. |
Source code in src/rational_functions/ratfunc.py
__rsub__(other)
Right subtract operator for RationalFunction.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
RationalFunction
|
Other rational function to subtract. |
required |
Returns:
Name | Type | Description |
---|---|---|
RationalFunction |
RationalFunction
|
Resulting rational function. |
Source code in src/rational_functions/ratfunc.py
__mul__(other)
Multiply two rational functions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
RationalFunction
|
Other rational function to multiply. |
required |
Returns:
Name | Type | Description |
---|---|---|
RationalFunction |
RationalFunction
|
Resulting rational function. |
Source code in src/rational_functions/ratfunc.py
__rmul__(other)
Right multiply operator for RationalFunction.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
RationalFunction
|
Other rational function to multiply. |
required |
Returns:
Name | Type | Description |
---|---|---|
RationalFunction |
RationalFunction
|
Resulting rational function. |
Source code in src/rational_functions/ratfunc.py
__truediv__(other)
Divide two rational functions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
RationalFunction
|
Other rational function to divide. |
required |
Returns:
Name | Type | Description |
---|---|---|
RationalFunction |
RationalFunction
|
Resulting rational function. |
Source code in src/rational_functions/ratfunc.py
__pow__(exponent)
Raise the rational function to a power.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exponent
|
int
|
Exponent to raise the rational function to. |
required |
Returns:
Name | Type | Description |
---|---|---|
RationalFunction |
RationalFunction
|
Resulting rational function. |
Source code in src/rational_functions/ratfunc.py
reciprocal(atol=None, rtol=None, ztol=None)
Get the reciprocal of the rational function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
atol
|
float | None
|
Absolute tolerance for root equivalence. Defaults to None. |
None
|
rtol
|
float | None
|
Relative tolerance for root equivalence. Defaults to None. |
None
|
ztol
|
float | None
|
Absolute tolerance below which imaginary or real part of roots will be approximated to zero. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
RationalFunction |
RationalFunction
|
Inverse of the rational function. |
Source code in src/rational_functions/ratfunc.py
deriv(m=1)
Differentiate the rational function in x.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
m
|
int
|
Order of the derivative. Defaults to 1. |
1
|
Returns:
Name | Type | Description |
---|---|---|
RationalFunction |
RationalFunction
|
Derivative of the rational function. |
Source code in src/rational_functions/ratfunc.py
integ(force_iobj=False)
Integrate the rational function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force_iobj
|
bool
|
Force the integral to be a RationalFunctionIntegral object. |
False
|
Returns:
Type | Description |
---|---|
Union[RationalFunctionIntegral, RationalFunction]
|
Union[RationalFunctionIntegral, RationalFunction]: Integral of the rational function. |
Source code in src/rational_functions/ratfunc.py
__call__(x)
Evaluate the rational function at given points.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
ArrayLike
|
Points to evaluate the function at. |
required |
Returns:
Name | Type | Description |
---|---|---|
ArrayLike |
ArrayLike
|
Evaluated values. |
Source code in src/rational_functions/ratfunc.py
__str__()
String representation of the rational function.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
String representation. |
Source code in src/rational_functions/ratfunc.py
from_fraction(numerator, denominator, atol=None, rtol=None, ztol=None)
classmethod
Construct a RationalFunction from a fraction of two polynomials.
Warning
This method requires finding the roots of the denominator polynomial. This will cause numerical inaccuracy, especially for high degree or ill-conditioned polynomials. Also, pay attention to the tolerances used to identify equivalent roots. In general, it is recommended to build the RationalFunction from its terms whenever possible.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
numerator
|
Polynomial | ArrayLike
|
Numerator polynomial, or series of coefficients in increasing order. |
required |
denominator
|
Polynomial | ArrayLike
|
Denominator polynomial, or series of coefficients in increasing order. |
required |
atol
|
float
|
Absolute tolerance for root equivalence. Defaults to None (use global setting). |
None
|
rtol
|
float
|
Relative tolerance for root equivalence. Defaults to None (use global setting). |
None
|
ztol
|
float
|
Absolute tolerance below which imaginary or real part of roots will be approximated to zero. Defaults to None (use global setting). |
None
|
Returns:
Name | Type | Description |
---|---|---|
RationalFunction |
RationalFunction
|
Rational function object. |
Source code in src/rational_functions/ratfunc.py
from_poles(numerator, poles, ztol=None)
classmethod
Construct a RationalFunction from a list of poles and a numerator polynomial. This method is more efficient and numerically stable than using the from_fraction method, especially for high degree or ill-conditioned denominators.
Note
The numerator polynomial should be scaled for a denominator polynomial with leading coefficient 1.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
numerator
|
Polynomial
|
Numerator polynomial. |
required |
poles
|
list[PolynomialRoot]
|
Poles of the rational function. |
required |
ztol
|
float
|
Absolute tolerance below which imaginary or real part of roots will be approximated to zero. Defaults to None (use global setting). |
None
|
Returns:
Name | Type | Description |
---|---|---|
RationalFunction |
RationalFunction
|
Rational function object. |
Source code in src/rational_functions/ratfunc.py
from_roots_and_poles(roots, poles, ztol=None)
classmethod
Construct a RationalFunction from a list of roots for the numerator and a list of poles for the denominator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
roots
|
list[PolynomialRoot]
|
Roots of the numerator. |
required |
poles
|
list[PolynomialRoot]
|
Poles of the denominator. |
required |
ztol
|
float
|
Absolute tolerance below which imaginary or real part of roots will be approximated to zero. Defaults to None (use global setting). |
None
|
Returns:
Name | Type | Description |
---|---|---|
RationalFunction |
RationalFunction
|
Rational function object. |
Source code in src/rational_functions/ratfunc.py
cauchy(x0, w)
classmethod
Construct a Cauchy distribution rational function, normalized to 1:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x0
|
float
|
Location parameter. |
required |
w
|
float
|
Scale parameter. |
required |
Returns:
Name | Type | Description |
---|---|---|
RationalFunction |
RationalFunction
|
Cauchy distribution rational function. |
Source code in src/rational_functions/ratfunc.py
set_approximation_options(atol=None, rtol=None, ztol=None)
classmethod
Set the approximation options for the rational function. They control how the poles of a rational function are grouped together and approximated. These are used as defaults in from_fraction, and whenever they can't be set by the user directly like in division.
Any value that is not passed gets left to its pre-existing value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
atol
|
float | None
|
Absolute tolerance to consider two poles identical. Defaults to None. |
None
|
rtol
|
float | None
|
Relative tolerance to consider two poles identical. Defaults to None. |
None
|
ztol
|
float | None
|
Absolute tolerance below which imaginary or real part of values will be approximated to zero. Defaults to None. |
None
|