Go to the documentation of this file.
26 #ifndef O2SCL_CHEB_APPROX_H
27 #define O2SCL_CHEB_APPROX_H
30 #include <o2scl/funct.h>
31 #include <o2scl/err_hnd.h>
33 #include <boost/numeric/ublas/vector.hpp>
35 #ifndef DOXYGEN_NO_O2NS
79 pi=boost::math::constants::pi<fp_t>();
98 if (
this==&gc)
return *
this;
119 template<
class func_t>
120 void init(func_t &func,
size_t ord, fp_t a1, fp_t b1) {
139 fp_t fac=two/((fp_t)(
order+1));
141 for(k=0;k<=
order;k++) {
142 fp_t y=cos(
pi*(k+half)/(
order+1));
143 f[k]=func(y*bma+bpa);
146 for(j=0;j<=
order;j++) {
148 for(k=0;k<=
order;k++) {
149 sum+=
f[k]*cos(
pi*j*(k+half)/((fp_t)(
order+1)));
160 template<
class vec_t>
void init(fp_t a1, fp_t b1,
161 size_t ord, vec_t &v) {
167 for(
size_t i=0;i<
order+1;i++)
c[i]=v[i];
176 size_t ord, vec_t &fval) {
195 fp_t fac=two/((fp_t)(
order+1));
197 for(j=0;j<=
order;j++) {
199 for(k=0;k<=
order; k++) {
200 sum+=fval[k]*cos(
pi*j*(k+half)/((fp_t)(
order+1)));
219 O2SCL_ERR(
"Series not initialized in cheb_approx::eval()",
228 fp_t y = (2*x-
a-
b)/(
b-
a);
231 for (i=
order; i >= 1; i--) {
237 return y*d1-d2+
c[0]/2;
254 if (n<
order) eval_order=n;
255 else eval_order=
order;
257 fp_t y = (2*x-
a-
b)/(
b-
a);
260 for (i = eval_order; i >= 1; i--) {
266 return y*d1-d2+
c[0]/2;
271 void eval_err(fp_t x, fp_t &result, fp_t &abserr) {
277 fp_t y = (2*x-
a-
b)/(
b-
a);
282 for (i =
order; i >= 1; i--) {
288 result = y*d1-d2+
c[0]/2;
292 for (i = 0; i <=
order; i++) {
298 fp_t dbl_eps=std::numeric_limits<fp_t>::epsilon();
308 void eval_n_err(
size_t n, fp_t x, fp_t &result, fp_t &abserr) {
313 fp_t y = (2*x-
a-
b)/(
b-
a);
319 if (n<
order) eval_order=n;
320 else eval_order=
order;
322 for (i = eval_order; i >= 1; i--) {
328 result = y*d1-d2+
c[0]/2;
332 for (i = 0; i <= eval_order; i++) {
336 fp_t dbl_eps=std::numeric_limits<fp_t>::epsilon();
356 (
"Requested invalid coefficient in cheb_approx::get_coefficient()",
371 (
"Requested invalid coefficient in cheb_approx::get_coefficient()",
386 for(
size_t i=0;i<
order+1 && i<n;i++) {
395 for(
size_t i=0;i<
order+1 && i<n;i++) {
409 const fp_t con=2/(
b-
a);
424 gc.
c[n-2]=2*(n-1)*
c[n-1];
427 gc.
c[i-3]=gc.
c[i-1]+2*(i-2)*
c[i-2];
443 const fp_t con=(
b-
a)/4;
467 for(
size_t i=1;i<=n-2;i++) {
468 gc.
c[i]=con*(
c[i-1]-
c[i+1])/((fp_t)i);
472 gc.
c[n-1]=con*
c[n-2]/(n-1);
473 sum += fac*gc.
c[n-1];
487 #ifndef DOXYGEN_NO_O2NS
fp_t b
Upper end of the interval.
void set_coefficient(size_t ix, fp_t co)
Set a coefficient.
The default vector type from uBlas.
fp_t eval(fp_t x) const
Evaluate the approximation.
cheb_approx_tl(const cheb_approx_tl &gc)
Copy constructor.
void get_coefficients(size_t n, vec_t &v) const
Get the coefficients.
void deriv(cheb_approx_tl &gc) const
Make gc an approximation to the derivative.
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
fp_t operator()(fp_t x) const
Evaluate the approximation.
fp_t eval_n(size_t n, fp_t x) const
Evaluate the approximation to a specified order.
void eval_n_err(size_t n, fp_t x, fp_t &result, fp_t &abserr)
Evaluate the approximation to a specified order and give the uncertainty.
fp_t get_coefficient(size_t ix) const
Get a coefficient.
cheb_approx_tl & operator=(const cheb_approx_tl &gc)
Copy constructor.
void set_coefficients(size_t n, const vec_t &v)
Set the coefficients.
@ exc_einval
invalid argument supplied by user
void init(fp_t a1, fp_t b1, size_t ord, vec_t &v)
Create an approximation from a vector of coefficients.
size_t order_sp
Single precision order.
void init(func_t &func, size_t ord, fp_t a1, fp_t b1)
Initialize a Chebyshev approximation of the function func over the interval from a1 to b1.
fp_t a
Lower end of the interval.
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
bool init_called
True if init has been called.
float o2abs(const float x)
Absolute value for single precision numbers.
void integ(cheb_approx_tl &gc) const
Make gc an approximation to the integral.
cheb_approx_tl< double > cheb_approx
Double-precision version of o2scl::cheb_approx_tl.
size_t order
Order of the approximation.
Chebyshev approximation (GSL)
void get_endpoints(fp_t &la, fp_t &lb)
Return the endpoints of the approximation.
void eval_err(fp_t x, fp_t &result, fp_t &abserr)
Evaluate the approximation and give the uncertainty.
void init_func_values(fp_t a1, fp_t b1, size_t ord, vec_t &fval)
Create an approximation from a vector of function values.
ubvector f
Function evaluated at Chebyshev points.
Documentation generated with Doxygen. Provided under the
GNU Free Documentation License (see License Information).