Commit a23987ec by Nils Rummler

### In CubicSplines kommt er mit den letzten 2 Konstruktor Überladungen nicht klar... daran anknüpfen

parent 26b1be22
 ... ... @@ -32,7 +32,7 @@ namespace ITABase * with M is a Matrix with only the 3 main diagonals nonequal zero, e the known excitation vector and x the vector of unknown variables. * Since the matrix dimension is n x n the excitatio, the middle and the returned vector are n elements big. Therefore the lower and the upper diagonale needs to have a length of n-1. */ ITA_BASE_API std::vector BandmatrixSolver(const std::vector& vdLower, const std::vector& vdMiddle, const std::vector& vdUpper, const std::vector& vdExcitation); ITA_BASE_API std::vector BandmatrixSolver(const std::vector& vdLower, const std::vector& vdMiddle, const std::vector& vdUpper, const std::vector& vdExcitation); } } ... ...
 ... ... @@ -41,7 +41,7 @@ namespace ITABase class ITA_BASE_API CPiecewisePolynomial { public: CPiecewisePolynomial(const std::vector& vdBreakPoints, const std::vector& vdCoeffs, const int iOrder); CPiecewisePolynomial(const std::vector& vdBreakPoints, const std::vector& vdCoeffs, const int iOrder); //! Returns the polynomial order inline int Order() const { return iOrder; }; ... ... @@ -50,16 +50,26 @@ namespace ITABase //! Returns the number of coefficients for a single polynomial inline int NumCoefficients() const { return Order() + 1; }; //! Returns the break points defining the intervals for the polynomials inline const std::vector& BreakPoints() const { return vdBreakPoints; }; inline const std::vector& BreakPoints() const { return vdBreakPoints; }; //! Returns the Coefficients of that Polynom. Sorted according to ascending intervals [a0, b0, c0, d0, a1, b1, c1, d1] inline const std::vector& Coefficients() const { return vdCoefficients; }; inline const std::vector& Coefficients() const { return vdCoefficients; }; //! Evaluate the piecewise polynomial at a given x value. If desired, xValues from outsite the breakpoints can be extrapolated linearly. float Value(const float& xValue, bool bExtrapolate = false) const; double Value(const double& xValue, bool bExtrapolate = false) const; //! Evaluate the piecewise polynomial at a given x value. If desired, xValues from outsite the breakpoints can be extrapolated linearly. double Value(const float& 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 Value(const std::vector& 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 Value(const std::vector& vdXValues, bool bExtrapolate = false) const; std::vector Value(const std::vector& vdXValues, 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 int IntervalIndex(const double xValue, 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 int IntervalIndex(const float xValue, bool bExtrapolate = false) const; //! Return a piecewise polynomial containing the derivations of the polynomials of this one CPiecewisePolynomial Derivation() const; ... ... @@ -69,13 +79,13 @@ namespace ITABase * The iterator ending this set of coefficients is then: * std::vector::const_iterator itEnd = itStart + NumCoefficients(); */ std::vector::const_iterator CoefficientsOfInterval(const int idxInterval) const; std::vector::const_iterator CoefficientsOfInterval(const int idxInterval) const; private: //! Order of polynomials int iOrder; //! Vector with break points. Defines the interval for each polynomial. std::vector vdBreakPoints; std::vector vdBreakPoints; //! Vector with all coefficients. Represents a 2D matrix: First dimension = number of intervals (pieces), second dimension = number of coefficients (order+1). /** * The Coefficients are arranged in groups for each interval (piece) starting the coefficient of highest order. Example: ... ... @@ -83,7 +93,7 @@ namespace ITABase * The coefficients for interval 1 represent the following polynomial: * f(x) = a1(x−x1)^3 + b1(x−x1)^2 + c1(x−x1) + d1 */ std::vector vdCoefficients; std::vector vdCoefficients; }; } } ... ...
 ... ... @@ -28,14 +28,25 @@ namespace ITABase namespace Math { //! Uses cubic splines to create a piecewise polynomial (order 3) for the given data pairs vdSupportingPoints and vdDataPoints. vdSupportingPoints need to be sorted in ascending order ITA_BASE_API CPiecewisePolynomial CubicSpline(const std::vector& vdSupportingPoints, const std::vector& vdDataPoints); //! Uses cubic splines to interpolate the function defined by the given data pairs vdSupportingPoints and vdDataPoints to a vector of points ITA_BASE_API std::vector CubicSpline(const std::vector& vdSupportingPoints, const std::vector& vdDataPoints, const std::vector& vdEvalPoints); //! Uses cubic splines to interpolate the function defined by the given data pairs vdSupportingPoints and vdDataPoints to a single point ITA_BASE_API float CubicSpline(const std::vector& vdSupportingPoints, const std::vector& vdDataPoints, float dEvalPoint); } ITA_BASE_API CPiecewisePolynomial CubicSpline(const std::vector& vdSupportingPoints, const std::vector& vdDataPoints); //All other Permutations of data Types //! Uses cubic splines to create a piecewise polynomial (order 3) for the given data pairs vdSupportingPoints and vdDataPoints. vdSupportingPoints need to be sorted in ascending order ITA_BASE_API CPiecewisePolynomial CubicSpline(const std::vector& vdSupportingPoints, const std::vector& vdDataPoints); //! Uses cubic splines to create a piecewise polynomial (order 3) for the given data pairs vdSupportingPoints and vdDataPoints. vdSupportingPoints need to be sorted in ascending order ITA_BASE_API CPiecewisePolynomial CubicSpline(const std::vector& vdSupportingPoints, const std::vector& vdDataPoints); //! Uses cubic splines to create a piecewise polynomial (order 3) for the given data pairs vdSupportingPoints and vdDataPoints. vdSupportingPoints need to be sorted in ascending order ITA_BASE_API CPiecewisePolynomial CubicSpline(const std::vector& vdSupportingPoints, const std::vector& vdDataPoints); //! Uses cubic splines to interpolate the function defined by the given data pairs vdSupportingPoints and vdDataPoints to a vector of points ITA_BASE_API std::vector CubicSpline(const std::vector& vdSupportingPoints, const std::vector& vdDataPoints, const std::vector& vdEvalPoints); //! Uses cubic splines to interpolate the function defined by the given data pairs vdSupportingPoints and vdDataPoints to a vector of points ITA_BASE_API std::vector CubicSpline(const std::vector& vdSupportingPoints, const std::vector& vdDataPoints, const std::vector& vdEvalPoints); //! Uses cubic splines to interpolate the function defined by the given data pairs vdSupportingPoints and vdDataPoints to a single point // ITA_BASE_API float CubicSpline(const std::vector& vdSupportingPoints, const std::vector& vdDataPoints, double dEvalPoint); } } #endif // IW_ITA_BASE_SPLINE
 ... ... @@ -5,7 +5,7 @@ using namespace ITABase; std::vector Math::BandmatrixSolver(const std::vector& vdLower, const std::vector& vdMiddle, const std::vector& vdUpper, const std::vector& vdExcitation) std::vector Math::BandmatrixSolver(const std::vector& vdLower, const std::vector& vdMiddle, const std::vector& vdUpper, const std::vector& vdExcitation) { //solving bandmatrix with Thomas Algorithm. Implementation according to "numerical recipees in C", William H. Press -2nd edition 1992, ISBN 0-521-43108-5, page 51 ... ... @@ -16,9 +16,9 @@ using namespace ITABase; const int iNum = vdMiddle.size(); std::vector vdGamma(iNum); float fBeta = vdMiddle[0]; std::vector vdSolution(iNum); // std::vector vdGamma(iNum); double fBeta = vdMiddle[0]; std::vector vdSolution(iNum); // vdSolution[0] = vdExcitation[0] / vdMiddle[0]; for (int idx = 1; idx < iNum; idx++) { ... ...
 ... ... @@ -9,7 +9,7 @@ using namespace ITABase; using namespace ITABase::Math; CPiecewisePolynomial::CPiecewisePolynomial(const std::vector& vdBreakPoints, const std::vector& vdCoeffs, const int iOrder) CPiecewisePolynomial::CPiecewisePolynomial(const std::vector& vdBreakPoints, const std::vector& vdCoeffs, const int iOrder) : iOrder(iOrder) , vdBreakPoints(vdBreakPoints) , vdCoefficients(vdCoeffs) ... ... @@ -26,8 +26,7 @@ CPiecewisePolynomial::CPiecewisePolynomial(const std::vector& vdBreakPoin ITA_EXCEPT_INVALID_PARAMETER("Invalid number of coefficients: Expected " + std::to_string(nCoeffs) + " but got " + std::to_string(vdCoeffs.size()) + "."); } float CPiecewisePolynomial::Value(const float & xValue, bool bExtrapolate) const double CPiecewisePolynomial::Value(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); ... ... @@ -38,28 +37,35 @@ float CPiecewisePolynomial::Value(const float & xValue, bool bExtrapolate) const if (xValue < vdBreakPoints[0]) iInterval = 0; else iInterval = NumIntervals(); float fX0 = vdBreakPoints[iInterval]; double fX0 = vdBreakPoints[iInterval]; return ppDerivative.Value(fX0) * ( xValue - fX0) + this->Value(fX0); //y=m(x-x0)+d } //inside bounds std::vector::const_iterator itCoef = CoefficientsOfInterval(iInterval); const float x0 = vdBreakPoints[iInterval]; float fResult = 0; std::vector::const_iterator itCoef = CoefficientsOfInterval(iInterval); const double x0 = vdBreakPoints[iInterval]; double fResult = 0; for (int idx = 0; idx <= iOrder; idx++) { //adding up the parts of the polynomial fResult += itCoef[idx] * pow(xValue - x0, iOrder - idx); } return fResult; } std::vector CPiecewisePolynomial::Value(const std::vector& vdXValues, bool bExtrapolate) const double CPiecewisePolynomial::Value(const float& xValue, bool bExtrapolate) const { return Value(float(xValue), bExtrapolate); } std::vector CPiecewisePolynomial::Value(const std::vector& vdXValues, bool bExtrapolate) const { std::vector result(vdXValues.size()); std::vector result(vdXValues.size()); for (int i = 0; i < vdXValues.size(); i++) result[i] = Value(vdXValues[i], bExtrapolate); return result; } int CPiecewisePolynomial::IntervalIndex(const float xValue, bool bExtrapolate) const std::vector CPiecewisePolynomial::Value(const std::vector& vdXValues, bool bExtrapolate) const { auto doubles_xValues = std::vector(vdXValues.begin(), vdXValues.end()); return Value(doubles_xValues, bExtrapolate); } int CPiecewisePolynomial::IntervalIndex(const double xValue, bool bExtrapolate) const { if (xValue < vdBreakPoints[0] || xValue > vdBreakPoints[NumIntervals()]) if (bExtrapolate) return -1; ... ... @@ -71,12 +77,17 @@ int CPiecewisePolynomial::IntervalIndex(const float xValue, bool bExtrapolate) c return NumIntervals()-1; //last possibility is xValue == last BreakPoint --> xValue in last interval } int CPiecewisePolynomial::IntervalIndex(const float xValue, bool bExtrapolate) const { return IntervalIndex(double(xValue), bExtrapolate); } CPiecewisePolynomial CPiecewisePolynomial::Derivation() const { const int iNewOrder = std::max(0, iOrder - 1); // Minimum order is zero const int iNewNumCoefficients = std::max(1, NumCoefficients() - 1); // At least one coefficient std::vector vdNewCoeffs( NumIntervals() * iNewNumCoefficients, 0.0); std::vector vdNewCoeffs( NumIntervals() * iNewNumCoefficients, 0.0); for (int idxPiece = 0; idxPiece < NumIntervals(); idxPiece++) { for (int idxCoeff = 0; idxCoeff < iOrder; idxCoeff++) ... ... @@ -91,7 +102,7 @@ CPiecewisePolynomial CPiecewisePolynomial::Derivation() const return CPiecewisePolynomial(vdBreakPoints, vdNewCoeffs, iNewOrder); } std::vector::const_iterator CPiecewisePolynomial::CoefficientsOfInterval(const int idxInterval) const std::vector::const_iterator CPiecewisePolynomial::CoefficientsOfInterval(const int idxInterval) const { if (idxInterval < 0 || idxInterval >= NumIntervals()) ITA_EXCEPT_INVALID_PARAMETER("Index for interval is out of bounds."); ... ...
 ... ... @@ -6,8 +6,29 @@ using namespace ITABase; using namespace ITABase::Math; //basic Constructors CPiecewisePolynomial Math::CubicSpline(const std::vector& vdSupportingPoints, const std::vector& vdDataPoints) CPiecewisePolynomial CubicSpline(const std::vector& vdSupportingPoints, const std::vector& vdDataPoints) { //Typecasting upwards to doubles auto doubles_SupportingPoints = std::vector(vdSupportingPoints.begin(), vdSupportingPoints.end()); auto doubles_DataPoints = std::vector(vdDataPoints.begin(), vdDataPoints.end()); return CubicSpline(doubles_SupportingPoints, doubles_DataPoints);//Constructor working with doubles } CPiecewisePolynomial CubicSpline(const std::vector& vdSupportingPoints, const std::vector& vdDataPoints) { //Typecasting upwards to doubles auto doubles_SupportingPoints = std::vector(vdSupportingPoints.begin(), vdSupportingPoints.end()); return CubicSpline(doubles_SupportingPoints, vdDataPoints);//Constructor working with doubles } CPiecewisePolynomial CubicSpline(const std::vector& vdSupportingPoints, const std::vector& vdDataPoints) { //Typecasting upwards to doubles auto doubles_DataPoints = std::vector(vdDataPoints.begin(), vdDataPoints.end()); return CubicSpline(vdSupportingPoints, doubles_DataPoints);//Constructor working with doubles } CPiecewisePolynomial ITABase::Math::CubicSpline(const std::vector& vdSupportingPoints, const std::vector& vdDataPoints) { /*setUp the bandmatrix M with the the h values. The vector with the coefficent b is called b. The vector with the linear approximations on the right hand side is called r. ... ... @@ -25,7 +46,7 @@ CPiecewisePolynomial Math::CubicSpline(const std::vector& vdSupportingPoi //Calculate h_i, formular 1.27b const int iPolynomialOrder = 3; const int iPoints = vdSupportingPoints.size(); std::vector vdH(iPoints - 1); std::vector vdH(iPoints - 1); for (int i = 0; i < iPoints - 1; i++) { vdH[i] = vdSupportingPoints[i + 1] - vdSupportingPoints[i]; ... ... @@ -35,7 +56,7 @@ CPiecewisePolynomial Math::CubicSpline(const std::vector& vdSupportingPoi } //SetUp the band matrix with lower, middle and upper diagonals. momentary only natural splines std::vector vdLower(iPoints - 3), vdMiddle(iPoints - 2), vdUpper(iPoints - 3); std::vector vdLower(iPoints - 3), vdMiddle(iPoints - 2), vdUpper(iPoints - 3); for (int i = 0; i < iPoints - 3; i++) { vdLower[i] = vdH[i + 1]; } ... ... @@ -47,17 +68,17 @@ CPiecewisePolynomial Math::CubicSpline(const std::vector& vdSupportingPoi //excitation vector //TODO only for natural splines with S0=S_iPoints = 0 std::vector vdR(iPoints - 2); std::vector vdR(iPoints - 2); for (int i = 0; i < iPoints - 2; i++) vdR[i] = 3 * ((vdDataPoints[i + 2] - vdDataPoints[i + 1]) / vdH[i + 1] - (vdDataPoints[i + 1] - vdDataPoints[i]) / vdH[i]); //solve bandmatrix and get the other coefficients std::vector vdB = BandmatrixSolver(vdLower, vdMiddle, vdUpper, vdR); std::vector vdB = BandmatrixSolver(vdLower, vdMiddle, vdUpper, vdR); vdB.insert(vdB.begin(), 0.0); std::vector vdA(iPoints - 1); std::vector vdC(iPoints - 1); std::vector vdD(iPoints - 1); std::vector vdA(iPoints - 1); std::vector vdC(iPoints - 1); std::vector vdD(iPoints - 1); vdB.push_back(0.0);//for ease of loop for (int i = 0; i < iPoints - 1; i++) { ... ... @@ -70,7 +91,7 @@ CPiecewisePolynomial Math::CubicSpline(const std::vector& vdSupportingPoi //sort for Constructor CPiecewisePolynomial int iCoefficients = (iPoints - 1) * (iPolynomialOrder + 1); std::vector vdCoefficients(iCoefficients); std::vector vdCoefficients(iCoefficients); int k = 0; for (int k = 0; k < iPoints - 1; k++) { vdCoefficients[4 * k] = vdA[k]; ... ... @@ -81,16 +102,25 @@ CPiecewisePolynomial Math::CubicSpline(const std::vector& vdSupportingPoi return CPiecewisePolynomial(vdSupportingPoints, vdCoefficients, iPolynomialOrder); } //Constructors with vectors std::vector CubicSpline(const std::vector& vdSupportingPoints, const std::vector& vdDataPoints, const std::vector& vdEvalPoints) { std::vector Math::CubicSpline(const std::vector& vdSupportingPoints, const std::vector& vdDataPoints, const std::vector& vdEvalPoints) CPiecewisePolynomial myPoly = CubicSpline(vdSupportingPoints, vdDataPoints); return myPoly.Value(vdEvalPoints); } /* std::vector CubicSpline(const std::vector& vdSupportingPoints, const std::vector& vdDataPoints, const std::vector& vdEvalPoints) { CPiecewisePolynomial myPoly = CubicSpline(vdSupportingPoints, vdDataPoints); return myPoly.Value(vdEvalPoints); } float Math::CubicSpline(const std::vector& vdSupportingPoints, const std::vector& vdDataPoints, float dEvalPoint) //Constructor for impatient users ;) float Math::CubicSpline(const std::vector& vdSupportingPoints, const std::vector& vdDataPoints, double dEvalPoint) { CPiecewisePolynomial myPoly = CubicSpline(vdSupportingPoints, vdDataPoints); return myPoly.Value(dEvalPoint); } \ No newline at end of file */ \ No newline at end of file
 ... ... @@ -28,12 +28,13 @@ using namespace ITABase::Math; bool SpeedTest() { /* //the following data is random. std::vector vdSupportingPoints{ -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; std::vector vdDataPoints2{ 77, 80, 19, 49, 45, 65, 71, 76, 28, 68, 66, 17,12, 50, 96, 35, 59, 23, 76, 26, 51 }; std::vector vdX = { -10, float(1.5), float(-7.898),float(3.3), float(3.3), float(9.9),float(-2.5),float(8.9),float(0.01),float(-4.3) }; std::vector vdSupportingPoints{ -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; std::vector vdDataPoints2{ 77, 80, 19, 49, 45, 65, 71, 76, 28, 68, 66, 17,12, 50, 96, 35, 59, 23, 76, 26, 51 }; std::vector vdX = { -10, 1.5, -7.898,3.3, 3.3,9.9,-2.5,8.9,0.01,-4.3 }; CPiecewisePolynomial myPoly = CubicSpline(vdSupportingPoints, vdDataPoints2); std::vector result(10); std::vector result(10); ITAStopWatch myWatch = ITAStopWatch(); std::cout << "Rueckgabe von piecwisePolynomial Objekten" << std::endl; ... ... @@ -52,14 +53,18 @@ bool SpeedTest() { myWatch.stop(); } std::cout << myWatch << std::endl; */ return true; } } //!creates one .txt file with the Points a spline function shall be constructed for and one with the cooeficients, this programm has computes. A third contains the coefficenc of the derivate. All can be read by the SplineTest.m into MATLAB. void Compare2MATLAB(){ /* //ALLES mit FLOATS //the following data is random. std::vector vdSupportingPoints{ -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; std::vector vdDataPoints{ 77, 80, 19, 49, 45, 65, 71, 76, 28, 68, 66, 17,12, 50, 96, 35, 59, 23, 76, 26, 51 }; std::vector vdX = { -10, float(1.5), float(-7.898),float(3.3), float(3.3), float(9.9),float(-2.5),float(8.9),float(0.01),float(-4.3) }; std::vector vdX = {-10, 1.5, -7.898,3.3, 3.3,9.9,-2.5,8.9,0.01,-4.3 }; CPiecewisePolynomial myPoly =CubicSpline(vdSupportingPoints, vdDataPoints); CPiecewisePolynomial myDerivate = myPoly.Derivation(); ... ... @@ -84,20 +89,52 @@ void Compare2MATLAB(){ } myFile.close(); return; //the following data is random. std::vector vdSupportingPoints{ -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; std::vector vdDataPoints{ 77, 80, 19, 49, 45, 65, 71, 76, 28, 68, 66, 17,12, 50, 96, 35, 59, 23, 76, 26, 51 }; std::vector vdX = { -10, 1.5, -7.898,3.3, 3.3,9.9,-2.5,8.9,0.01,-4.3 }; CPiecewisePolynomial myPoly = CubicSpline(vdSupportingPoints, vdDataPoints); CPiecewisePolynomial myDerivate = myPoly.Derivation(); std::vector vdCoeff = myPoly.Coefficients(); std::ofstream myFile; myFile.open("points.txt"); for (int k = 0; k < vdDataPoints.size(); k++) { myFile << vdSupportingPoints[k] << ", " << vdDataPoints[k] << std::endl; } myFile.close(); myFile.open("coeff.txt"); for (int k = 0; k < vdDataPoints.size() - 1; k++) { myFile << vdCoeff[4 * k] << ", " << vdCoeff[4 * k + 1] << ", " << vdCoeff[4 * k + 2] << ", " << vdCoeff[4 * k + 3] << std::endl; } myFile.close(); vdCoeff = myDerivate.Coefficients(); myFile.open("derivate.txt"); for (int k = 0; k < vdDataPoints.size() - 1; k++) { myFile << vdCoeff[3 * k] << ", " << vdCoeff[3 * k + 1] << ", " << vdCoeff[3 * k + 2] << std::endl; } myFile.close(); */ return; } //!Checks the general behavior of the code bool GeneralTest(){ /*//ALLES mit FLOATS //the following data is random. std::vector vdSupportingPoints{ -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; std::vector vdDataPoints{ 77, 80, 19, 49, 45, 65, 71, 76, 28, 68, 66, 17,12, 50, 96, 35, 59, 23, 76, 26, 51 }; std::vector vdX = { -10, float(1.5), float(-7.898),float(3.3), float(3.3), float(9.9),float(-2.5),float(8.9),float(0.01),float(-4.3) }; const std::vector vdSupportingPoints{ -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; const std::vector vdDataPoints{ 77, 80, 19, 49, 45, 65, 71, 76, 28, 68, 66, 17,12, 50, 96, 35, 59, 23, 76, 26, 51 }; const std::vector vdX = {-10, 1.5f, -7.898f,3.3f, 3.3f,9.9f,-2.5f,8.9f,0.01f,-4.3f }; CPiecewisePolynomial myPoly = CubicSpline(vdSupportingPoints, vdDataPoints); std::cout << "-------Starting with FLOAT values-------" << std::endl << std::endl; std::cout << "At supportion Point 0, the calculated value should be 66: " << myPoly.Value(0) << std::endl; //should get specific Value std::cout << "At random Point x=0.5 the spline should interpolate ~40.9: " << myPoly.Value(0.5) << std::endl; /* std::vector vdBreakPoints = { 0, 1 }; std::vector vdCoeff = { 1,1,1 }; int iOrder = 2; ... ... @@ -146,10 +183,77 @@ bool GeneralTest(){ std::cout << err << std::endl; } return true; */ /* //the following data is random. std::vector vdSupportingPoints{ -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; std::vector vdDataPoints{ 77, 80, 19, 49, 45, 65, 71, 76, 28, 68, 66, 17,12, 50, 96, 35, 59, 23, 76, 26, 51 }; std::vector vdX = { -10, 1.5, -7.898,3.3, 3.3,9.9,-2.5,8.9,0.01,-4.3 }; CPiecewisePolynomial myPoly = CubicSpline(vdSupportingPoints, vdDataPoints); std::cout< vdBreakPoints = { 0, 1 }; std::vector vdCoeff = { 1,1,1 }; int iOrder = 2; CPiecewisePolynomial myPoly2 = CPiecewisePolynomial(vdBreakPoints, vdCoeff, iOrder); //deviation test CPiecewisePolynomial myPoly3 = myPoly2.Derivation(); std::cout << "The deviation of x^2+x+1 should be: " << myPoly3.Coefficients()[0] << " * x + " << myPoly3.Coefficients()[1] << std::endl; std::cout << "so the new polynoial only got " << myPoly3.NumCoefficients() << " coefficients." << std::endl; //exceptions for Piecewise Polynoms std::cout << "Testing the Value function with Argument out of it's range, without extrapolation:" << std::endl; try { myPoly2.Value(-2); } 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.Value(-2, true) << std::endl; std::cout << "At 2, the calculated value should be 6: " << myPoly2.Value(2, true) << std::endl; //exceptions for spline std::cout << "Testing spline with to few Points:" << std::endl; try { std::vector vdSupportingPoints{ -10, -9 }; std::vector vdDataPoints{ 77, 80 }; myPoly = CubicSpline(vdSupportingPoints, vdDataPoints); } catch (ITAException& err) { std::cout << err << std::endl; } std::cout << "Testing non matching dimensions:" << std::endl; try { std::vector vdSupportingPoints{ -10, -5 ,-1,0,3 };//5points std::vector vdDataPoints{ 77, 80,4,5,-4,-1 };//6 Points myPoly = CubicSpline(vdSupportingPoints, vdDataPoints); } catch (ITAException& err) { std::cout << err << std::endl; } std::cout << "Testing with non ascending supportingPoints" << std::endl; try { std::vector vdSupportingPoints{ -10, 5 ,-1,0,3 }; std::vector vdDataPoints{ 77, 80,4,5,-4 }; myPoly = CubicSpline(vdSupportingPoints, vdDataPoints); } catch (ITAException& err) { std::cout << err << std::endl; } */ return true; } //! SplineTest.cpp consists of several Test for Speed, functionality and DataExport to MATLAB, to compare and plot splines int main(int iNumInArgs, char* pcInArgs[]) { /* std::cout << "Checking starts" << std::endl; std::cout << "Test 1: general Test for functions" << std::endl << std::endl; GeneralTest(); ... ... @@ -158,6 +262,6 @@ int main(int iNumInArgs, char* pcInArgs[]) std::cout << "The next function will write 3 .txt files that need to be imported to MATLAB with the help of SplineTest.m" << std::endl; Compare2MATLAB(); */ return 0; }
 ... ... @@ -16,5 +16,5 @@ -75.4804, 119.925, -20.4449, 35 77.5513, -106.516, -7.03549, 59 -85.725, 126.138, 12.5868, 23 73.3487, -131.037, 7.68815, 76 73.3487, -131.037, 7.68816, 76 -29.6697, 89.0092, -34.3395, 26
 ... ... @@ -4,7 +4,7 @@ 100.69, -121.813, 23.343 -66.0135, 79.568, 2.22051 49.3634, -52.459, 15.775 -92.4402, 46.2679, 12.6795 -92.4403, 46.2679, 12.6795 164.398, -138.613, -33.4929 -142.15, 190.183, -7.70791 14.2029, -94.1177, 40.3245 ... ... @@ -16,5 +16,5 @@ -226.441, 239.85, -20.4449 232.654, -213.032, -7.03549 -257.175, 252.276, 12.5868 220.046, -262.074, 7.68815 220.046, -262.074, 7.68816 -89.0092, 178.018, -34.3395
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!