Commit 56c3d48b authored by Nils Rummler's avatar Nils Rummler
Browse files

Vollstaendige implementierung für float und double eingabeparameter. erweiterung der Testfunktion

parent a23987ec
......@@ -37,12 +37,14 @@ namespace ITABase
* Coefficients [a0, b0, c0, d0, a1, b1, c1, d1] belong to interval 0 [x0, x1] and interval 1 [x1, x2] respectively.
* The coefficients for interval 1 represent the following polynomial of order 3:
* f(x) = a1(x−x1)^3 + b1(x−x1)^2 + c1(x−x1) + d1
*
* All data is internally computed as values of type double. Nevertheless there are overloaded functions for input of type float. These are converted internally.
*/
class ITA_BASE_API CPiecewisePolynomial
{
public:
CPiecewisePolynomial(const std::vector<double>& vdBreakPoints, const std::vector<double>& vdCoeffs, const int iOrder);
CPiecewisePolynomial(const std::vector<float>& vdBreakPnts, const std::vector<float>& vdCoeffs, const int iOrder);
//! Returns the polynomial order
inline int Order() const { return iOrder; };
//! Returns the number of intervals (pieces) between break points
......
......@@ -41,10 +41,12 @@ namespace ITABase
//! 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<double> CubicSpline(const std::vector<double>& vdSupportingPoints, const std::vector<double>& vdDataPoints, const std::vector<double>& 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<double> CubicSpline(const std::vector<float>& vdSupportingPoints, const std::vector<float>& vdDataPoints, const std::vector<float>& vdEvalPoints);
ITA_BASE_API std::vector<double> CubicSpline(const std::vector<float>& vdSupportingPoints, const std::vector<float>& vdDataPoints, const std::vector<float>& 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<double>& vdSupportingPoints, const std::vector<double>& vdDataPoints, double dEvalPoint);
ITA_BASE_API double CubicSpline(const std::vector<double>& vdSupportingPoints, const std::vector<double>& vdDataPoints, double dEvalPoint);
//! Uses cubic splines to interpolate the function defined by the given data pairs vdSupportingPoints and vdDataPoints to a single point. BEWARE of the internal conversion to type double!
ITA_BASE_API float CubicSpline(const std::vector<float>& vdSupportingPoints, const std::vector<float>& vdDataPoints, float dEvalPoint);
}
}
......
......@@ -25,6 +25,30 @@ CPiecewisePolynomial::CPiecewisePolynomial(const std::vector<double>& vdBreakPoi
if (vdCoeffs.size() != nCoeffs)
ITA_EXCEPT_INVALID_PARAMETER("Invalid number of coefficients: Expected " + std::to_string(nCoeffs) + " but got " + std::to_string(vdCoeffs.size()) + ".");
}
CPiecewisePolynomial::CPiecewisePolynomial(const std::vector<float>& vdBreakPnts, const std::vector<float>& vdCoeffs, const int iOrder)
: iOrder(iOrder)
{
/*
auto doubles_BreakPoints = std::vector<double>(vdBreakPnts.begin(), vdBreakPnts.end());
auto double_vdCoeffs = std::vector<double>(vdCoeffs.begin(), vdCoeffs.end());
CPiecewisePolynomial(doubles_BreakPoints, double_vdCoeffs, iOrder);
*/
auto doubles_BreakPoints = std::vector<double>(vdBreakPnts.begin(), vdBreakPnts.end());
auto double_vdCoeffs = std::vector<double>(vdCoeffs.begin(), vdCoeffs.end());
vdCoefficients = double_vdCoeffs;
vdBreakPoints = doubles_BreakPoints;
if (iOrder < 0)
ITA_EXCEPT_INVALID_PARAMETER("Polynom order must be greater or equal zero.");
const int iMinimumNBreakPoints = 2; // At least one interval
if (vdBreakPnts.size() < iMinimumNBreakPoints)
ITA_EXCEPT_INVALID_PARAMETER("Number of break points not sufficient for polynom order: Expected " + std::to_string(iMinimumNBreakPoints) + " but got " + std::to_string(vdBreakPoints.size()) + ".");
const int nCoeffs = NumIntervals() * (iOrder + 1);
if (vdCoeffs.size() != nCoeffs)
ITA_EXCEPT_INVALID_PARAMETER("Invalid number of coefficients: Expected " + std::to_string(nCoeffs) + " but got " + std::to_string(vdCoeffs.size()) + ".");
}
double CPiecewisePolynomial::Value(const double & xValue, bool bExtrapolate) const
{
......@@ -51,7 +75,7 @@ double CPiecewisePolynomial::Value(const double & xValue, bool bExtrapolate) con
}
double CPiecewisePolynomial::Value(const float& xValue, bool bExtrapolate) const
{
return Value(float(xValue), bExtrapolate);
return Value(double(xValue), bExtrapolate);
}
std::vector<double> CPiecewisePolynomial::Value(const std::vector<double>& vdXValues, bool bExtrapolate) const
{
......
......@@ -7,27 +7,6 @@
using namespace ITABase;
using namespace ITABase::Math;
//basic Constructors
CPiecewisePolynomial CubicSpline(const std::vector<float>& vdSupportingPoints, const std::vector<float>& vdDataPoints)
{
//Typecasting upwards to doubles
auto doubles_SupportingPoints = std::vector<double>(vdSupportingPoints.begin(), vdSupportingPoints.end());
auto doubles_DataPoints = std::vector<double>(vdDataPoints.begin(), vdDataPoints.end());
return CubicSpline(doubles_SupportingPoints, doubles_DataPoints);//Constructor working with doubles
}
CPiecewisePolynomial CubicSpline(const std::vector<float>& vdSupportingPoints, const std::vector<double>& vdDataPoints)
{
//Typecasting upwards to doubles
auto doubles_SupportingPoints = std::vector<double>(vdSupportingPoints.begin(), vdSupportingPoints.end());
return CubicSpline(doubles_SupportingPoints, vdDataPoints);//Constructor working with doubles
}
CPiecewisePolynomial CubicSpline(const std::vector<double>& vdSupportingPoints, const std::vector<float>& vdDataPoints)
{
//Typecasting upwards to doubles
auto doubles_DataPoints = std::vector<double>(vdDataPoints.begin(), vdDataPoints.end());
return CubicSpline(vdSupportingPoints, doubles_DataPoints);//Constructor working with doubles
}
CPiecewisePolynomial ITABase::Math::CubicSpline(const std::vector<double>& vdSupportingPoints, const std::vector<double>& vdDataPoints)
{
/*setUp the bandmatrix M with the the h values. The vector with the coefficent b is called b.
......@@ -102,25 +81,49 @@ CPiecewisePolynomial ITABase::Math::CubicSpline(const std::vector<double>& vdSup
return CPiecewisePolynomial(vdSupportingPoints, vdCoefficients, iPolynomialOrder);
}
//Constructors with vectors
std::vector<double> CubicSpline(const std::vector<double>& vdSupportingPoints, const std::vector<double>& vdDataPoints, const std::vector<double>& vdEvalPoints)
CPiecewisePolynomial ITABase::Math::CubicSpline(const std::vector<float>& vdSupportingPoints, const std::vector<float>& vdDataPoints)
{
//Typecasting upwards to doubles
auto doubles_SupportingPoints = std::vector<double>(vdSupportingPoints.begin(), vdSupportingPoints.end());
auto doubles_DataPoints = std::vector<double>(vdDataPoints.begin(), vdDataPoints.end());
return CubicSpline(doubles_SupportingPoints, doubles_DataPoints);//Constructor working with doubles
}
CPiecewisePolynomial ITABase::Math::CubicSpline(const std::vector<float>& vdSupportingPoints, const std::vector<double>& vdDataPoints)
{
//Typecasting upwards to doubles
auto doubles_SupportingPoints = std::vector<double>(vdSupportingPoints.begin(), vdSupportingPoints.end());
return CubicSpline(doubles_SupportingPoints, vdDataPoints);//Constructor working with doubles
}
CPiecewisePolynomial ITABase::Math::CubicSpline(const std::vector<double>& vdSupportingPoints, const std::vector<float>& vdDataPoints)
{
//Typecasting upwards to doubles
auto doubles_DataPoints = std::vector<double>(vdDataPoints.begin(), vdDataPoints.end());
return CubicSpline(vdSupportingPoints, doubles_DataPoints);//Constructor working with doubles
}
//Constructors returning evaluated Points
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);
}
/*
std::vector<double> CubicSpline(const std::vector<float>& vdSupportingPoints, const std::vector<float>& vdDataPoints, const std::vector<float>& vdEvalPoints)
std::vector<double> ITABase::Math::CubicSpline(const std::vector<float>& vdSupportingPoints, const std::vector<float>& vdDataPoints, const std::vector<float>& vdEvalPoints)
{
CPiecewisePolynomial myPoly = CubicSpline(vdSupportingPoints, vdDataPoints);
return myPoly.Value(vdEvalPoints);
}
//Constructor for impatient users ;)
float Math::CubicSpline(const std::vector<double>& vdSupportingPoints, const std::vector<double>& vdDataPoints, double dEvalPoint)
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);
}
*/
\ No newline at end of file
float ITABase::Math::CubicSpline(const std::vector<float>& vdSupportingPoints, const std::vector<float>& vdDataPoints, float dEvalPoint)
{
CPiecewisePolynomial myPoly = CubicSpline(vdSupportingPoints, vdDataPoints);
return float(myPoly.Value(dEvalPoint));
}
......@@ -28,8 +28,10 @@
using namespace ITABase::Math;
bool SpeedTest() {
/*
//the following data is random.
std::cout << std::endl << "zuerst wird der benchmark mit DOUBLES ausgefuert:" << std::endl;
std::vector<double> vdSupportingPoints{ -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
std::vector<double> vdDataPoints2{ 77, 80, 19, 49, 45, 65, 71, 76, 28, 68, 66, 17,12, 50, 96, 35, 59, 23, 76, 26, 51 };
std::vector<double> vdX = { -10, 1.5, -7.898,3.3, 3.3,9.9,-2.5,8.9,0.01,-4.3 };
......@@ -53,88 +55,87 @@ bool SpeedTest() {
myWatch.stop();
}
std::cout << myWatch << std::endl;
*/
myWatch.reset();
//JETZT MIT FLOAT
std::cout << std::endl << "Nun wird das gleiche noch mit FLOATS wiederholt:" << std:: endl;
std::vector<float> vdSupportingPoints_float{ -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
std::vector<float> vdDataPoints2_float{ 77, 80, 19, 49, 45, 65, 71, 76, 28, 68, 66, 17,12, 50, 96, 35, 59, 23, 76, 26, 51 };
std::vector<float> vdX_float = { float(-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) };
CPiecewisePolynomial myPoly_float = CubicSpline(vdSupportingPoints_float, vdDataPoints2_float);
std::vector<float> result_float(10);
std::cout << "Rueckgabe von piecwisePolynomial Objekten" << std::endl;
for (int k = 0; k < 100; k++) {
myWatch.start();
myPoly_float = CubicSpline(vdSupportingPoints_float, vdDataPoints2_float);
myWatch.stop();
}
std::cout << myWatch << std::endl;
myWatch.reset();
std::cout << "Rueckgabe von vector Objekten" << std::endl;
for (int k = 0; k < 100; k++) {
myWatch.start();
result = CubicSpline(vdSupportingPoints_float, vdDataPoints2_float, vdX_float);
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<float> vdSupportingPoints{ -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
std::vector<float> vdDataPoints{ 77, 80, 19, 49, 45, 65, 71, 76, 28, 68, 66, 17,12, 50, 96, 35, 59, 23, 76, 26, 51 };
std::vector<float> 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<float> 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();
//the following data is random.
std::vector<double> vdSupportingPoints{ -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
std::vector<double> vdDataPoints{ 77, 80, 19, 49, 45, 65, 71, 76, 28, 68, 66, 17,12, 50, 96, 35, 59, 23, 76, 26, 51 };
std::vector<double> 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();
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();
std::vector<double> 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();
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;
//the following data is random.
std::vector<double> vdSupportingPoints{ -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
std::vector<double> vdDataPoints{ 77, 80, 19, 49, 45, 65, 71, 76, 28, 68, 66, 17,12, 50, 96, 35, 59, 23, 76, 26, 51 };
std::vector<double> 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();
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();
std::vector<double> 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();
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();
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
//ALLES mit FLOATS
//the following data is random.
const std::vector<float> 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<float> 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<float> 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;
std::cout << "At supportion Point 0, the calculated value should be 66: " << myPoly.Value(float(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::cout << "At random Point x=0.5 the spline should interpolate ~40.9: " << myPoly.Value(float(0.5)) << std::endl;
/*
std::vector<float> vdBreakPoints = { 0, 1 };
std::vector<float> vdCoeff = { 1,1,1 };
int iOrder = 2;
......@@ -147,13 +148,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.Value(-2); }
try { myPoly2.Value(float(-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;
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;
//exceptions for spline
std::cout<<"Testing spline with to few Points:" << std::endl;
try {
......@@ -182,47 +183,49 @@ bool GeneralTest(){
catch (ITAException& err) {
std::cout << err << std::endl;
}
return true;
*/
/*
//
// ALLES MIT DOUBLES
//
//the following data is random.
std::vector<double> vdSupportingPoints{ -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
std::vector<double> vdDataPoints{ 77, 80, 19, 49, 45, 65, 71, 76, 28, 68, 66, 17,12, 50, 96, 35, 59, 23, 76, 26, 51 };
std::vector<double> 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::vector<double> vdSupportingPoints_double{ -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
std::vector<double> vdDataPoints_double{ 77, 80, 19, 49, 45, 65, 71, 76, 28, 68, 66, 17,12, 50, 96, 35, 59, 23, 76, 26, 51 };
std::vector<double> vdX_double = { -10, 1.5, -7.898,3.3, 3.3,9.9,-2.5,8.9,0.01,-4.3 };
CPiecewisePolynomial myPoly_double = CubicSpline(vdSupportingPoints_double, vdDataPoints_double);
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.Value(0) << std::endl;
std::cout << "At supportion Point 0, the calculated value should be 66: " << myPoly_double.Value(0.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::cout << "At random Point x=0.5 the spline should interpolate ~40.9: " << myPoly_double.Value(0.5) << std::endl;
std::vector<double> vdBreakPoints = { 0, 1 };
std::vector<double> vdCoeff = { 1,1,1 };
int iOrder = 2;
CPiecewisePolynomial myPoly2 = CPiecewisePolynomial(vdBreakPoints, vdCoeff, iOrder);
std::vector<double> vdBreakPoints_double = { 0, 1 };
std::vector<double> vdCoeff_double = { 1,1,1 };
int iOrder2 = 2;
CPiecewisePolynomial myPoly2_double = CPiecewisePolynomial(vdBreakPoints_double, vdCoeff_double, iOrder2);
//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;
CPiecewisePolynomial myPoly3_double = myPoly2_double.Derivation();
std::cout << "The deviation of x^2+x+1 should be: " << myPoly3_double.Coefficients()[0] << " * x + " << myPoly3_double.Coefficients()[1] << std::endl;
std::cout << "so the new polynoial only got " << myPoly3_double.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); }
try { myPoly2_double.Value(-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.Value(-2, true) << std::endl;
std::cout << "At 2, the calculated value should be 6: " << myPoly2.Value(2, true) << 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;
//exceptions for spline
std::cout << "Testing spline with to few Points:" << std::endl;
try {
std::vector<double> vdSupportingPoints{ -10, -9 };
std::vector<double> vdDataPoints{ 77, 80 };
myPoly = CubicSpline(vdSupportingPoints, vdDataPoints);
myPoly_double = CubicSpline(vdSupportingPoints, vdDataPoints);
}
catch (ITAException& err) {
std::cout << err << std::endl;
......@@ -231,7 +234,7 @@ bool GeneralTest(){
try {
std::vector<double> vdSupportingPoints{ -10, -5 ,-1,0,3 };//5points
std::vector<double> vdDataPoints{ 77, 80,4,5,-4,-1 };//6 Points
myPoly = CubicSpline(vdSupportingPoints, vdDataPoints);
myPoly_double = CubicSpline(vdSupportingPoints, vdDataPoints);
}
catch (ITAException& err) {
std::cout << err << std::endl;
......@@ -240,12 +243,25 @@ bool GeneralTest(){
try {
std::vector<double> vdSupportingPoints{ -10, 5 ,-1,0,3 };
std::vector<double> vdDataPoints{ 77, 80,4,5,-4 };
myPoly = CubicSpline(vdSupportingPoints, vdDataPoints);
myPoly_double = CubicSpline(vdSupportingPoints, vdDataPoints);
}
catch (ITAException& err) {
std::cout << err << std::endl;
}
*/
//
// JETZT ALLE PERMUTATIONEN AN BERGABEPARAMETERN FR DIE KONSTRUKTOREN TESTEN
//
CPiecewisePolynomial mySpline1 = CubicSpline(vdSupportingPoints, vdDataPoints);
CPiecewisePolynomial mySpline2 = CubicSpline(vdSupportingPoints_double, vdDataPoints);
CPiecewisePolynomial mySpline3 = CubicSpline(vdSupportingPoints, vdDataPoints_double);
CPiecewisePolynomial mySpline4 = CubicSpline(vdSupportingPoints_double, vdDataPoints_double);
std::vector<double> myResult1 = CubicSpline(vdSupportingPoints_double, vdDataPoints_double,vdX_double);
std::vector<double> myResult2 = CubicSpline(vdSupportingPoints, vdDataPoints, vdX);
float myResult3 = CubicSpline(vdSupportingPoints, vdDataPoints, float(1));
double myResult4 = CubicSpline(vdSupportingPoints_double, vdDataPoints_double, double(1));
std::cout<< std::endl << "Es wurden erfolgreich alle Konstruktoren getestet" << std::endl;
return true;
}
......@@ -253,7 +269,7 @@ bool GeneralTest(){
//! 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();
......@@ -262,6 +278,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;
}
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