Commit bf84e6c4 authored by Philipp Schäfer's avatar Philipp Schäfer
Browse files

PiecewisePolynomial

- renamed Value methods to Evaluate
parent 05c3fe81
......@@ -58,13 +58,13 @@ namespace ITABase
//! Returns the Coefficients of that Polynom. Sorted according to ascending intervals [a0, b0, c0, d0, a1, b1, c1, d1]
inline const std::vector<double>& Coefficients() const { return vdCoefficients; };
//! Evaluate the piecewise polynomial at a given x value. If desired, xValues from outsite the breakpoints can be extrapolated linearly.
double Value(const double& xValue, bool bExtrapolate = false) const;
//! Evaluates the piecewise polynomial at a given x value. If desired, xValues from outsite the breakpoints can be extrapolated linearly.
double Evaluate(const double& xValue, bool bExtrapolate = false) const;
//! Evaluates the piecewise polynomial at all given x values. If desired, xValues from outsite the breakpoints can be extrapolated linearly.
std::vector<double> Value(const std::vector<double>& vdXValues, bool bExtrapolate = false) const;
std::vector<double> Evaluate(const std::vector<double>& vdXValues, bool bExtrapolate = false) const;
//! Evaluates the piecewise polynomial at all given x values. If desired, xValues from outsite the breakpoints can be extrapolated linearly.
std::vector<double> Value(const std::vector<float>& vfXValues, bool bExtrapolate = false) const;
std::vector<double> Evaluate(const std::vector<float>& vfXValues, bool bExtrapolate = false) const;
//! Finds the index of Interval at a given x value. If extrapolation is desired, it will return -1 for xValue outsite the breakpoints
......
......@@ -32,7 +32,7 @@ CPiecewisePolynomial::CPiecewisePolynomial(const std::vector<float>& vfBreakPoin
}
double CPiecewisePolynomial::Value(const double & xValue, bool bExtrapolate) const
double CPiecewisePolynomial::Evaluate(const double & xValue, bool bExtrapolate) const
{
//a(x-x0)^(n) + b(x-x0)^(n-1) + c(x-x0)^(n-2) +...
int iInterval = IntervalIndex(xValue, bExtrapolate);
......@@ -44,7 +44,7 @@ double CPiecewisePolynomial::Value(const double & xValue, bool bExtrapolate) con
else iInterval = NumIntervals();
double fX0 = vdBreakPoints[iInterval];
return ppDerivative.Value(fX0) * ( xValue - fX0) + this->Value(fX0); //y=m(x-x0)+d
return ppDerivative.Evaluate(fX0) * ( xValue - fX0) + this->Evaluate(fX0); //y=m(x-x0)+d
}
//inside bounds
......@@ -56,18 +56,18 @@ double CPiecewisePolynomial::Value(const double & xValue, bool bExtrapolate) con
}
return fResult;
}
std::vector<double> CPiecewisePolynomial::Value(const std::vector<double>& vdXValues, bool bExtrapolate) const
std::vector<double> CPiecewisePolynomial::Evaluate(const std::vector<double>& vdXValues, bool bExtrapolate) const
{
std::vector<double> result(vdXValues.size());
for (int i = 0; i < vdXValues.size(); i++)
result[i] = Value(vdXValues[i], bExtrapolate);
result[i] = Evaluate(vdXValues[i], bExtrapolate);
return result;
}
std::vector<double> CPiecewisePolynomial::Value(const std::vector<float>& vfXValues, bool bExtrapolate) const
std::vector<double> CPiecewisePolynomial::Evaluate(const std::vector<float>& vfXValues, bool bExtrapolate) const
{
std::vector<double> result(vfXValues.size());
for (int i = 0; i < vfXValues.size(); i++)
result[i] = Value(vfXValues[i], bExtrapolate);
result[i] = Evaluate(vfXValues[i], bExtrapolate);
return result;
}
......
......@@ -108,24 +108,24 @@ CPiecewisePolynomial ITABase::Math::CubicSpline(const std::vector<double>& vdSup
std::vector<double> ITABase::Math::CubicSpline(const std::vector<double>& vdSupportingPoints, const std::vector<double>& vdDataPoints, const std::vector<double>& vdEvalPoints)
{
CPiecewisePolynomial myPoly = CubicSpline(vdSupportingPoints, vdDataPoints);
return myPoly.Value( vdEvalPoints );
return myPoly.Evaluate( vdEvalPoints );
}
std::vector<double> ITABase::Math::CubicSpline(const std::vector<float>& vfSupportingPoints, const std::vector<float>& vfDataPoints, const std::vector<float>& vfEvalPoints)
{
CPiecewisePolynomial myPoly = CubicSpline(vfSupportingPoints, vfDataPoints);
return myPoly.Value( vfEvalPoints );
return myPoly.Evaluate( vfEvalPoints );
}
double ITABase::Math::CubicSpline(const std::vector<double>& vdSupportingPoints, const std::vector<double>& vdDataPoints, double dEvalPoint)
{
CPiecewisePolynomial myPoly = CubicSpline(vdSupportingPoints, vdDataPoints);
return myPoly.Value( dEvalPoint );
return myPoly.Evaluate( dEvalPoint );
}
float ITABase::Math::CubicSpline(const std::vector<float>& vfSupportingPoints, const std::vector<float>& vfDataPoints, float fEvalPoint)
{
CPiecewisePolynomial myPoly = CubicSpline(vfSupportingPoints, vfDataPoints);
return float( myPoly.Value(fEvalPoint) );
return float( myPoly.Evaluate(fEvalPoint) );
}
......@@ -127,9 +127,9 @@ bool GeneralTest(){
std::cout << "-------Starting with FLOAT values-------" << std::endl << std::endl;
std::cout << "At supportion Point 0, the calculated value should be 66: " << myPoly.Value(float(0)) << std::endl;
std::cout << "At supportion Point 0, the calculated value should be 66: " << myPoly.Evaluate(float(0)) << std::endl;
//should get specific Value
std::cout << "At random Point x=0.5 the spline should interpolate ~40.9: " << myPoly.Value(float(0.5)) << std::endl;
std::cout << "At random Point x=0.5 the spline should interpolate ~40.9: " << myPoly.Evaluate(float(0.5)) << std::endl;
std::vector<float> vfBreakPoints = { 0, 1 };
......@@ -149,7 +149,7 @@ bool GeneralTest(){
//exceptions for Piecewise Polynoms
std::cout << "Testing the Value function with Argument out of it's range, without extrapolation:" << std::endl;
bool ok = false;
try { myPoly2.Value(float(-2)); }
try { myPoly2.Evaluate(float(-2)); }
catch (ITAException& err) {
ok = true;
std::cout << err;
......@@ -159,8 +159,8 @@ bool GeneralTest(){
std::cout << std::endl << std::endl;
std::cout << "Testing the Value function with Arguments out of it's range, with extrapolation:" << std::endl;
std::cout << "At -2, the calculated value should be -1: " << myPoly2.Value(float(-2),true) << std::endl;
std::cout << "At 2, the calculated value should be 6: " << myPoly2.Value(float(2), true) << std::endl;
std::cout << "At -2, the calculated value should be -1: " << myPoly2.Evaluate(float(-2),true) << std::endl;
std::cout << "At 2, the calculated value should be 6: " << myPoly2.Evaluate(float(2), true) << std::endl;
std::cout << std::endl;
//exceptions for spline
......@@ -222,9 +222,9 @@ bool GeneralTest(){
std::cout<<std::endl << "-------continuing with DOUBLE values-------" << std::endl << std::endl;
std::cout << "At supportion Point 0, the calculated value should be 66: " << myPoly_double.Value(0.0) << std::endl;
std::cout << "At supportion Point 0, the calculated value should be 66: " << myPoly_double.Evaluate(0.0) << std::endl;
//should get specific Value
std::cout << "At random Point x=0.5 the spline should interpolate ~40.9: " << myPoly_double.Value(0.5) << std::endl;
std::cout << "At random Point x=0.5 the spline should interpolate ~40.9: " << myPoly_double.Evaluate(0.5) << std::endl;
std::vector<double> vdBreakPoints_double = { 0, 1 };
......@@ -239,13 +239,13 @@ bool GeneralTest(){
//exceptions for Piecewise Polynoms
std::cout << "Testing the Value function with Argument out of it's range, without extrapolation:" << std::endl;
try { myPoly2_double.Value(-2.0); }
try { myPoly2_double.Evaluate(-2.0); }
catch (ITAException& err) {
std::cout << err << std::endl;
}
std::cout << "Testing the Value function with Arguments out of it's range, with extrapolation:" << std::endl;
std::cout << "At -2, the calculated value should be -1: " << myPoly2_double.Value(-2.0, true) << std::endl;
std::cout << "At 2, the calculated value should be 6: " << myPoly2_double.Value(2.0, true) << std::endl;
std::cout << "At -2, the calculated value should be -1: " << myPoly2_double.Evaluate(-2.0, true) << std::endl;
std::cout << "At 2, the calculated value should be 6: " << myPoly2_double.Evaluate(2.0, true) << std::endl;
//exceptions for spline
std::cout << "Testing spline with to few Points:" << std::endl;
try {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment