[193] | 1 | // $Id: GSLInterpolation.cc 1650 2008-12-14 22:13:48Z jari $ |
---|
| 2 | |
---|
[675] | 3 | /* |
---|
[1643] | 4 | Copyright (C) 2008 Jari Häkkinen |
---|
[193] | 5 | |
---|
[1437] | 6 | This file is part of the yat library, http://dev.thep.lu.se/yat |
---|
[193] | 7 | |
---|
[675] | 8 | The yat library is free software; you can redistribute it and/or |
---|
| 9 | modify it under the terms of the GNU General Public License as |
---|
[1486] | 10 | published by the Free Software Foundation; either version 3 of the |
---|
[675] | 11 | License, or (at your option) any later version. |
---|
| 12 | |
---|
| 13 | The yat library is distributed in the hope that it will be useful, |
---|
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 16 | General Public License for more details. |
---|
| 17 | |
---|
| 18 | You should have received a copy of the GNU General Public License |
---|
[1487] | 19 | along with yat. If not, see <http://www.gnu.org/licenses/>. |
---|
[675] | 20 | */ |
---|
| 21 | |
---|
[1643] | 22 | #include "GSLInterpolation.h" |
---|
[675] | 23 | |
---|
[1644] | 24 | #include "yat/utility/VectorBase.h" |
---|
[1643] | 25 | |
---|
| 26 | #include <cassert> |
---|
| 27 | |
---|
[193] | 28 | namespace theplu { |
---|
[680] | 29 | namespace yat { |
---|
[383] | 30 | namespace regression { |
---|
[193] | 31 | |
---|
[703] | 32 | |
---|
[1643] | 33 | GSLInterpolation::GSLInterpolation(const gsl_interp_type* interpolator_type, |
---|
[1644] | 34 | const utility::VectorBase& x, |
---|
| 35 | const utility::VectorBase& y) |
---|
[1650] | 36 | : evaluation_(0.0), gsl_status_(0) |
---|
[703] | 37 | { |
---|
[1643] | 38 | assert(x.size()==y.size()); |
---|
| 39 | size_t size=x.size(); |
---|
| 40 | x_=new double[size]; |
---|
| 41 | y_=new double[size]; |
---|
| 42 | for (size_t i=0; i<size; ++i) { |
---|
| 43 | x_[i]=x(i); |
---|
| 44 | y_[i]=y(i); |
---|
| 45 | } |
---|
[1644] | 46 | interpolator_ = gsl_interp_alloc(interpolator_type, size); |
---|
[1650] | 47 | gsl_status_=gsl_interp_init(interpolator_, x_, y_, size); |
---|
[1643] | 48 | accelerator_ = gsl_interp_accel_alloc(); |
---|
[703] | 49 | } |
---|
[713] | 50 | |
---|
[718] | 51 | |
---|
[1643] | 52 | GSLInterpolation::~GSLInterpolation(void) |
---|
[718] | 53 | { |
---|
[1643] | 54 | gsl_interp_free(interpolator_); |
---|
| 55 | gsl_interp_accel_free(accelerator_); |
---|
| 56 | delete x_; |
---|
| 57 | delete y_; |
---|
[718] | 58 | } |
---|
| 59 | |
---|
| 60 | |
---|
[1648] | 61 | size_t GSLInterpolation::bsearch(const double x_array[], double x, |
---|
| 62 | size_t index_lo, size_t index_hi) const |
---|
| 63 | { |
---|
| 64 | return gsl_interp_bsearch(x_array, x, index_lo, index_hi); |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | |
---|
[1650] | 68 | int GSLInterpolation::error_status(void) const |
---|
| 69 | { |
---|
| 70 | return gsl_status_; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | |
---|
[1648] | 74 | double GSLInterpolation::evaluate(double x) |
---|
[1650] | 75 | { |
---|
| 76 | gsl_status_=gsl_interp_eval_e(interpolator_, x_, y_, x, accelerator_, |
---|
| 77 | &evaluation_); |
---|
| 78 | return evaluation_; |
---|
[221] | 79 | } |
---|
| 80 | |
---|
[726] | 81 | |
---|
[1648] | 82 | double GSLInterpolation::evaluate_derivative(double x) |
---|
| 83 | { |
---|
[1650] | 84 | gsl_status_=gsl_interp_eval_deriv_e(interpolator_, x_, y_, x, accelerator_, |
---|
| 85 | &evaluation_); |
---|
| 86 | return evaluation_; |
---|
[1648] | 87 | } |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | double GSLInterpolation::evaluate_derivative2(double x) |
---|
| 91 | { |
---|
[1650] | 92 | gsl_status_=gsl_interp_eval_deriv2_e(interpolator_, x_, y_, x, accelerator_, |
---|
| 93 | &evaluation_); |
---|
| 94 | return evaluation_; |
---|
[1648] | 95 | } |
---|
| 96 | |
---|
| 97 | |
---|
| 98 | double GSLInterpolation::evaluate_integral(double a, double b) |
---|
| 99 | { |
---|
[1650] | 100 | gsl_status_=gsl_interp_eval_integ_e(interpolator_, x_, y_, a, b, |
---|
| 101 | accelerator_, &evaluation_); |
---|
| 102 | return evaluation_; |
---|
[1648] | 103 | } |
---|
| 104 | |
---|
| 105 | |
---|
[1650] | 106 | double GSLInterpolation::evaluation(void) const |
---|
| 107 | { |
---|
| 108 | return evaluation_; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | |
---|
[1648] | 112 | unsigned int GSLInterpolation::min_size(void) const |
---|
| 113 | { |
---|
| 114 | return gsl_interp_min_size(interpolator_); |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | |
---|
[681] | 118 | }}} // of namespaces regression, yat, and theplu |
---|