MLIB
Loading...
Searching...
No Matches
poly.h File Reference

Polynomial evaluation using Horner's scheme. More...

#include <array>
#include <vector>

Go to the source code of this file.

Functions

template<typename T >
mlib::poly (T x, const T *coeff, int n)
 Evaluate a polynomial using Horner's scheme.
 
template<typename T , size_t N>
mlib::poly (T x, std::array< T, N > coeff)
 Evaluate a polynomial using Horner's scheme.
 
template<typename T >
mlib::poly (T x, std::vector< T > coeff)
 Evaluate a polynomial using Horner's scheme.
 

Detailed Description

Polynomial evaluation using Horner's scheme.

(c) Mircea Neacsu 2020

Function Documentation

◆ poly() [1/3]

template<typename T >
T mlib::poly ( x,
const T *  coeff,
int  n 
)

Evaluate a polynomial using Horner's scheme.

Parameters
xEvaluation point
coeffpolynomial coefficients in order from lowest power (coeff[0]) to highest power (coeff[N-1])
nsize of coefficient's array.
Returns
Polynomial value in point x coeff[n-1]*x^(n-1) + coeff[n-2]*x^(n-2) + ... + coeff[1]*x + coeff[0]

◆ poly() [2/3]

template<typename T , size_t N>
T mlib::poly ( x,
std::array< T, N >  coeff 
)

Evaluate a polynomial using Horner's scheme.

Parameters
xEvaluation point
coeffarray of polynomial coefficients in order from lowest power (coeff[0]) to highest power (coeff[N-1])
Returns
Polynomial value in point x coeff[N-1]*x^(N-1) + coeff[N-2]*x^(N-2) + ... + coeff[1]*x + coeff[0]

This template function will generate a new instantiation for each array size.

◆ poly() [3/3]

template<typename T >
T mlib::poly ( x,
std::vector< T >  coeff 
)

Evaluate a polynomial using Horner's scheme.

Parameters
xEvaluation point
coeffvector of polynomial coefficients in order from lowest power (coeff[0]) to highest power (coeff[N-1])
Returns
Polynomial value in point x coeff[N-1]*x^(N-1) + coeff[N-2]*x^(N-2) + ... + coeff[1]*x + coeff[0]