// \$Id: interpolation_test.cc 1656 2008-12-17 13:52:51Z jari \$ /* Copyright (C) 2008 Jari Hðkkinen This file is part of the yat library, http://dev.thep.lu.se/yat The yat library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. The yat library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with yat. If not, see . */ #include "Suite.h" #include "yat/regression/AkimaInterpolation.h" #include "yat/regression/AkimaPeriodicInterpolation.h" #include "yat/regression/CSplineInterpolation.h" #include "yat/regression/CSplinePeriodicInterpolation.h" #include "yat/regression/LinearInterpolation.h" #include "yat/regression/PolynomialInterpolation.h" #include "yat/utility/Vector.h" #include "yat/utility/VectorConstView.h" #include int main(int argc, char* argv[]) { using namespace theplu::yat; using namespace theplu::yat::regression; test::Suite suite(argc, argv); /* The test data is computed with R version 2.7.2 (2008-08-25) on MacBook Pro Intel CPU running MacOSX 10.5.5 x <- c(13,17,19,22,27,35) y <- c(100,97,111,120,117,103) cspline <- splinefun(x,y,"natural") w <- seq(15,25,1) z <- cspline(w) z  94.11579 93.91382 97.00000 103.66776 111.00000 116.02563 118.76822  120.00000 120.38499 120.15443 119.43138 */ utility::Vector x(6); utility::Vector y(6); x(0)= 13; x(1)= 17; x(2)= 19; x(3)= 22; x(4)= 27; x(5)= 35; y(0)=100; y(1)= 97; y(2)=111; y(3)=120; y(4)=117; y(5)=103; CSplineInterpolation cspline(x,y); utility::Vector w(11); utility::Vector z(11); w( 0)=15; z( 0)= 94.11579; w( 1)=16; z( 1)= 93.91382; w( 2)=17; z( 2)= 97; w( 3)=18; z( 3)=103.66776; w( 4)=19; z( 4)=111; w( 5)=20; z( 5)=116.02563; w( 6)=21; z( 6)=118.76822; w( 7)=22; z( 7)=120; w( 8)=23; z( 8)=120.38499; w( 9)=24; z( 9)=120.15443; w(10)=25; z(10)=119.43138; for (size_t i=0; i 1e-5) { suite.err() << "cspline test failed for i=" << i << std::endl; suite.err() << " difference between target and interpolation too large: " << fabs(cspline.evaluate(w(i))-z(i)) << std::endl; suite.add(false); } // Check for errors if (cspline.error_status()) { suite.err() << "cspline test failed with GSL_EDOM error" << std::endl; suite.add(false); } } // An error should be generated, if not test fails cspline.evaluate(w(0)-5); if (!cspline.error_status()) { suite.err() << "cspline test failed no GSL_EDOM error occured" << std::endl; suite.add(false); } // lazy testing, at least try to create the objects AkimaInterpolation(x,y); AkimaPeriodicInterpolation(x,y); CSplinePeriodicInterpolation(x,y); LinearInterpolation(x,y); PolynomialInterpolation(x,y); return suite.return_value(); }