VF_ratioVD_ratioVE_ratio
VF_ratio_dVF_ratio_eVD_ratio_e
VFx_ratioVDx_ratioVEx_ratio
VFx_ratio_dVFx_ratio_eVDx_ratio_e
VF_ratioOddEvenVD_ratioOddEvenVE_ratioOddEven
VF_ratioOddEven_dVF_ratioOddEven_eVD_ratioOddEven_e
VFx_ratioOddEvenVDx_ratioOddEvenVEx_ratioOddEven
VFx_ratioOddEven_dVFx_ratioOddEven_eVDx_ratioOddEven_e
VF_ratioEvenOddVD_ratioEvenOddVE_ratioEvenOdd
VF_ratioEvenOdd_dVF_ratioEvenOdd_eVD_ratioEvenOdd_e
VFx_ratioEvenOddVDx_ratioEvenOddVEx_ratioEvenOdd
VFx_ratioEvenOdd_dVFx_ratioEvenOdd_eVDx_ratioEvenOdd_e
   
VFu_ratioVDu_ratioVEu_ratio
VFu_ratio_dVFu_ratio_eVDu_ratio_e
VFux_ratioVDux_ratioVEux_ratio
VFux_ratio_dVFux_ratio_eVDux_ratio_e
VFu_ratioOddEvenVDu_ratioOddEvenVEu_ratioOddEven
VFu_ratioOddEven_dVFu_ratioOddEven_eVDu_ratioOddEven_e
VFux_ratioOddEvenVDux_ratioOddEvenVEux_ratioOddEven
VFux_ratioOddEven_dVFux_ratioOddEven_eVDux_ratioOddEven_e
VFu_ratioEvenOddVDu_ratioEvenOddVEu_ratioEvenOdd
VFu_ratioEvenOdd_dVFu_ratioEvenOdd_eVDu_ratioEvenOdd_e
VFux_ratioEvenOddVDux_ratioEvenOddVEux_ratioEvenOdd
VFux_ratioEvenOdd_dVFux_ratioEvenOdd_eVDux_ratioEvenOdd_e
FunctionRational expression: ratio of two polynomials
Syntax C/C++#include <VFmath.h>
int VF_ratio( fVector Y, fVector X, ui size, fVector Coeff, unsigned degP, unsigned degQ );
int VFx_ratio( fVector Y, fVector X, ui size, fVector Coeff, unsigned degP, unsigned degQ, float A, float B );
int VFu_ratio( fVector Y, fVector X, ui size, fVector Coeff, unsigned degP, unsigned degQ );
int VFux_ratio( fVector Y, fVector X, ui size, fVector Coeff, unsigned degP, unsigned degQ, float A, float B );
C++ VecObj#include <OptiVec.h>
int vector<T>::ratio( const vector<T>& X, const vector<T>& Coeff, unsigned degP, unsigned degQ );
int vector<T>::x_ratio( const vector<T>& X, const vector<T>& Coeff, unsigned degP, unsigned degQ, const T& A, const T& B );
Pascal/Delphiuses VFmath;
function VF_ratio( Y, X:fVector; size:UIntSize; Coeff:fVector; degP, degQ:UInt ): IntBool;
function VFx_ratio( Y, X:fVector; size:UIntSize; Coeff:fVector; degP, degQ:UInt; A, B:Single ): IntBool;
function VFu_ratio( Y, X:fVector; size:UIntSize; Coeff:fVector; degP, degQ:UInt ): IntBool;
function VFux_ratio( Y, X:fVector; size:UIntSize; Coeff:fVector; degP, degQ:UInt; A, B:Single ): IntBool;
CUDA function C/C++#include <cudaVFmath.h>
int cudaVF_ratio( fVector d_Y, fVector d_X, ui size, fVector h_Coeff, unsigned degP, unsigned degQ );
int cusdVF_ratio( fVector d_Y, fVector d_X, ui size, fVector d_Coeff, unsigned degP, unsigned degQ );
int cudaVFx_ratio( fVector d_Y, fVector d_X, ui size, fVector h_Coeff, unsigned degP, unsigned degQ, float A, float B );
int cusdVFx_ratio( fVector d_Y, fVector d_X, ui size, fVector d_Coeff, unsigned degP, unsigned degQ, float *d_A, float *d_B );
int cudaVFu_ratio( fVector d_Y, fVector d_X, ui size, fVector h_Coeff, unsigned degP, unsigned degQ );
int cusdVFu_ratio( fVector d_Y, fVector d_X, ui size, fVector d_Coeff, unsigned degP, unsigned degQ );
int cudaVFux_ratio( fVector d_Y, fVector d_X, ui size, fVector h_Coeff, unsigned degP, unsigned degQ, float A, float B );
int cusdVFux_ratio( fVector d_Y, fVector d_X, ui size, fVector d_Coeff, unsigned degP, unsigned degQ, float *d_A, float *d_B );
int VFcu_ratio( fVector h_Y, fVector h_X, ui size, fVector h_Coeff, unsigned degP, unsigned degQ );
int VFxcu_ratio( fVector h_Y, fVector h_X, ui size, fVector h_Coeff, unsigned degP, unsigned degQ, float A, float B );
int VFucu_ratio( fVector h_Y, fVector h_X, ui size, fVector h_Coeff, unsigned degP, unsigned degQ );
int VFuxcu_ratio( fVector h_Y, fVector h_X, ui size, fVector h_Coeff, unsigned degP, unsigned degQ, float A, float B );
CUDA function Pascal/Delphiuses VFmath;
function cudaVF_ratio( d_Y, d_X:fVector; size:UIntSize; h_Coeff:fVector; degP, degQ:UInt ): IntBool;
function cusdVF_ratio( d_Y, d_X:fVector; size:UIntSize; d_Coeff:fVector; degP, degQ:UInt ): IntBool;
function cudaVFx_ratio( d_Y, d_X:fVector; size:UIntSize; h_Coeff:fVector; degP, degQ:UInt; A, B:Single ): IntBool;
function cusdVFx_ratio( d_Y, d_X:fVector; size:UIntSize; d_Coeff:fVector; degP, degQ:UInt; d_A, d_B:PSingle ): IntBool;
function cudaVFu_ratio( d_Y, d_X:fVector; size:UIntSize; h_Coeff:fVector; degP, degQ:UInt ): IntBool;
function cusdVFu_ratio( d_Y, d_X:fVector; size:UIntSize; d_Coeff:fVector; degP, degQ:UInt ): IntBool;
function cudaVFux_ratio( d_Y, d_X:fVector; size:UIntSize; h_Coeff:fVector; degP, degQ:UInt; A, B:Single ): IntBool;
function cusdVFux_ratio( d_Y, d_X:fVector; size:UIntSize; d_Coeff:fVector; degP, degQ:UInt; d_A, d_B:PSingle ): IntBool;
function VFcu_ratio( h_Y, h_X:fVector; size:UIntSize; h_Coeff:fVector; degP, degQ:UInt ): IntBool;
function VFxcu_ratio( h_Y, h_X:fVector; size:UIntSize; h_Coeff:fVector; degP, degQ:UInt; A, B:Single ): IntBool;
function VFucu_ratio( h_Y, h_X:fVector; size:UIntSize; h_Coeff:fVector; degP, degQ:UInt ): IntBool;
function VFuxcu_ratio( h_Y, h_X:fVector; size:UIntSize; h_Coeff:fVector; degP, degQ:UInt; A, B:Single ): IntBool;
Descriptionsimple versions VF_ratio, VD_ratio, VE_ratio:
Yi = P/Q, with
P = p0 + p1 * Xi + p2 * Xi2 + ... + pdegP * XidegP,
Q = q0 + q1 * Xi + q2 * Xi2 + ... + qdegQ * XidegQ

expanded versions VFx_ratio, VDx_ratio, VEx_ratio:
xi = (A*Xi + B),
Yi = P/Q as above with xi instead of Xi

A polynomial P of degree degP is divided by a polynomial Q of degree degQ. The coefficients pk and qk are taken from the vector Coeff. Coeff must contain the constant term p0 as element no. 0, the linear coefficient p1 as element no. 1, and so one until pdegP as element no. degP immediately followed by q0 as element no. (degP+1), q1 as element no. (degP+2) etc., until qdegQ as element no. (degP+degQ+1). This means that Coeff contains a total of (degP+degQ+2) elements.

"unprotected" versions (prefix VFu_,   VFux_, etc.):
These functions do not perform any error handling, which makes them much faster (up to 50%) than the standard versions. They do, however, indicate in their return value, if an error occurred.

Even in the case that the individual polynomials P and Q might overflow, their ratio still might yield a perfectly legal result. Therefore, OptiVec offers additional versions which internally employ higher accuracy (and range): VF_ratio_d and VF_ratio_e work in double or extended precision, resp., before converting the result back to single precision. Likewise, VD_ratio_e works in extended precision (even if the compiler does not support extended precision!), before converting the result back to double. These versions exist only on the CPU, not in CUDA.

When rational models are used for the approximation of mathematical functions, sometimes one of the polynomials only consists of odd terms, while the other polynomial has only even terms. Examples are the rational representation of the tangent function (P has only odd terms, Q has only even terms) or of the cotangent function (P has only even terms, Q has only odd terms). These cases are covered by the following OptiVec functions:

VF_ratioOddEven: P has only odd terms, Q has only even terms:
Pi = p1 * Xi + p1 * Xi3 + ... + pdegP * XidegP, with degP = 2n+1
Qi = q0 + q2 * Xi2 + ... + qdegQ * XidegQ, with degQ = 2n
Coeff here contains (degP+1)/2 + (degQ/2)+1 coefficients.

VF_ratioEvenOdd: P has only even, Q has only odd terms:
Pi = p0 + p2 * Xi2 + ... + pdegP * XidegP, with degP = 2n
Qi = q1 * Xi + q1 * Xi3 + ... + qdegQ * XidegQ, with degQ = 2n+1
Coeff here contains (degP/2)+1 + (degQ+1)/2 coefficients.

While mathematically legal, round-off error makes polynomials and, by extension, rations of high degrees practically useless. In the present implementation, VF_ratio, VF_ratio_d, and VD_ratio allow degP+degQ ± 32. Above that, an error message "Invalid Parameter(s)" is emitted and program execution halted. Only the VE_ versions along with VF_ratio_e and VD_ratio_e allow to evaluate ratios of higher degrees.

Error handlingOVERFLOW or ZERODIVIDE errors lead to the result ±HUGE_VAL. 0/0 situations are solved only in the VE_ and ratio_e versions, where 0/0 is replaced by the first derivative of P divided by the first derivative of Q. In all other versions, 0/0 leads to the result ±HUGE_VAL.
Return valueFALSE (0), if no error occured; otherwise a bit combination of the error codes, 0x4 (division by 0), 0x8 (OVERFLOW), and 0x1 (0/0).
Although the "unprotected" variants (prefixes VFu_,   VFux_, etc.) do not actually hande errors, they return the same error codes as the normal variant.
See alsoVF_poly,   VF_ipow,   VF_pow

VectorLib Table of Contents  OptiVec home