MBSim

Project Page
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes
MBSim::PiecewisePolynomFunction< Ret(Arg)> Class Template Reference

class for piecewise-polynomials and cubic spline interpolation More...

#include <piecewise_polynom_function.h>

Inheritance diagram for MBSim::PiecewisePolynomFunction< Ret(Arg)>:
MBSim::Function< Ret(Arg)> Function

List of all members.

Classes

class  FirstDerivative
 piecewise polynomial interpolation - first derivative More...
class  SecondDerivative
 piecewise polynomial interpolation - second derivative More...
class  ZerothDerivative
 piecewise polynomial interpolation - zeroth derivative More...

Public Types

enum  InterpolationMethod { cSplinePeriodic, cSplineNatural, piecewiseLinear }

Public Member Functions

Ret operator() (const Arg &x)
fmatvec::Der< Ret, Arg >::type parDer (const Arg &x)
fmatvec::Der< typename
fmatvec::Der< Ret, double >
::type, double >::type 
parDerParDer (const double &x)
void setXF (const fmatvec::VecV &x, const fmatvec::MatV &f, InterpolationMethod method=cSplineNatural)
 set interpolation
std::vector< fmatvec::MatV > getCoefs ()
fmatvec::VecV getBreaks ()
void setPP (const std::vector< fmatvec::MatV > &coefs_u, const fmatvec::Vec &breaks_u)
 set piecewise polynomial
virtual void initializeUsingXML (xercesc::DOMElement *element)
 initialize function with XML code

Protected Member Functions

void calculateSplinePeriodic (const fmatvec::VecV &x, const fmatvec::MatV &f)
 calculation of periodic spline by interpolation
void calculateSplineNatural (const fmatvec::VecV &x, const fmatvec::MatV &f)
 calculation of natural spline by interpolation
void calculatePLinear (const fmatvec::VecV &x, const fmatvec::MatV &f)

Protected Attributes

std::vector< fmatvec::MatV > coefs
 vector of polynomial coefficents
fmatvec::Vec breaks
 vector of breaks (interval boundaries)
int nPoly
 number of defined piecewise polynomials
int order
 order of polynomial (3 for cubic polynomials)
int index
 for internal use in ppeval functions

Private Attributes

ZerothDerivative f
FirstDerivative fd
SecondDerivative fdd

Detailed Description

template<typename Ret, typename Arg>
class MBSim::PiecewisePolynomFunction< Ret(Arg)>

class for piecewise-polynomials and cubic spline interpolation

Author:
Robert Huber
Date:
2006-08-31 initial commit
2006-09-05 verified with matlab /octave (Robert Huber)
2008-05-21 C++ beauty treatment, PLinear (Thorsten Schindler)
2009-08-11 kernel_dev (Thorsten Schindler)
Todo:
add deletes TODO

Spline / PP-Form info Piecewise polynomial: $ c0 xloc^n + c1 xloc^{n-1} + c2 xloc^{n-2} + \dots + cn $ with [c0 c1 c2 ... cn] ith row vector of coefs-matrix breaks(i) << x << breaks(i+1) defines i and xloc = x-breaks(i)

Ex. cubic spline with breaks= [0; 0.3; 0.5] coefs= [d1 c1 b1 a1; d2 c2 b2 a2]

\[ S(x) = a1 + b1 xloc + c1 xloc^2 + d1 xloc^3 for x\in[0;0.3] \text{and} x_loc = x \]

\[ S(x) = a2 + b2 xloc + c2 xloc^2 + d2 xloc^3 for x\in[0.3;0.5] \text{and} xloc = x - 0.3 \]

Cubic spline (xi,fi) i=1..N is being interpolated by N-1 piecewise polynomials Si of degree 3 yielding a global $ C^2 $ curve for uniqueness TWO additional boundary conditions are necessary (periodic / natural)

Piecewise linear polynomial (xi,fi) i=1..N is being interpolated by N-1 piecewise polynomials Si of degree 1 yielding a globally weak differentiable curve in the context of this class the second derivative is defined to be zero everywhere (which is mathematically wrong)


Member Function Documentation

template<typename Ret , typename Arg >
void MBSim::PiecewisePolynomFunction< Ret(Arg)>::calculateSplineNatural ( const fmatvec::VecV &  x,
const fmatvec::MatV &  f 
) [protected]

calculation of natural spline by interpolation

Parameters:
interpolatedarguments
interpolatedfunction values
template<typename Ret , typename Arg >
void MBSim::PiecewisePolynomFunction< Ret(Arg)>::calculateSplinePeriodic ( const fmatvec::VecV &  x,
const fmatvec::MatV &  f 
) [protected]

calculation of periodic spline by interpolation

Parameters:
interpolatedarguments
interpolatedfunction values
template<typename Ret , typename Arg >
fmatvec::VecV MBSim::PiecewisePolynomFunction< Ret(Arg)>::getBreaks ( ) [inline]
Returns:
interval boundaries
template<typename Ret , typename Arg >
std::vector<fmatvec::MatV> MBSim::PiecewisePolynomFunction< Ret(Arg)>::getCoefs ( ) [inline]
Returns:
polynomial coefficients
template<typename Ret , typename Arg >
void MBSim::PiecewisePolynomFunction< Ret(Arg)>::initializeUsingXML ( xercesc::DOMElement *  element) [virtual]

initialize function with XML code

Parameters:
XMLelement

Reimplemented from MBSim::Function< Ret(Arg)>.

template<typename Ret , typename Arg >
void MBSim::PiecewisePolynomFunction< Ret(Arg)>::setPP ( const std::vector< fmatvec::MatV > &  coefs_u,
const fmatvec::Vec &  breaks_u 
) [inline]

set piecewise polynomial

Parameters:
polynomialcoefficients
intervalboundaries
template<typename Ret , typename Arg >
void MBSim::PiecewisePolynomFunction< Ret(Arg)>::setXF ( const fmatvec::VecV &  x,
const fmatvec::MatV &  f,
InterpolationMethod  method = cSplineNatural 
) [inline]

set interpolation

Parameters:
xvector of ordered x values
fcorresponding f(x) values (rowwise)
InterpolationMethod'cSplinePeriodic' -> cubic Spline with periodic end conditions (two-times continuously differentiable) S(x1) = S(xN) -> f(0)=f(end) S'(x1) = S'(xN) S''(x1) = S''(xN) 'cSplineNatural' -> cubic Spline with natural end conditions (two-times continuously differentiable) S''(x1) = S''(xN) = 0 'piecewiseLinear' -> piecewise linear function (weak differentiable)

The documentation for this class was generated from the following file: