00001 #ifndef __FUNC_H__ 00002 #define __FUNC_H__ 00003 00004 #include "linalg.hpp" 00005 #include <gsl/gsl_deriv.h> 00006 00007 namespace bvp{ 00008 using namespace linalg; 00009 00010 //A real-valued function from R^n to R. 00011 class realfunc{ 00012 public: 00013 realfunc(); 00014 realfunc( double(*f)(const point&)); 00015 virtual ~realfunc(){}; 00016 00017 void set_function_ptr(double (f_in)(const point &p)); 00018 00019 double operator()(const point& p) const; 00020 virtual double at(const point& p) const; 00021 00022 //Derivatives in directions k, k1, k2. 00023 virtual double d(const point& x, size_t k) const; 00024 virtual double d2(const point& x, size_t k1, size_t k2) const ; 00025 protected: 00026 static double eps; 00027 static double sqrteps; 00028 static double root3eps; 00029 static bool initialised ; 00030 private: 00031 double (*myfunc)(const point &p); 00032 void no_init(int line, string file) const; //For throwing exceptions 00033 }; 00034 00035 00036 //A function wrapper for calling GSL derivatives. 00037 class gsl_function_wrapper{ 00038 public: 00039 gsl_function_wrapper(const realfunc &f, point p, size_t idx); 00040 void set_params( const realfunc &f, point p, size_t idx); 00041 gsl_function* get_gsl_function() const; 00042 00043 static double takemyaddress(double xi, void* nothing); 00044 private: 00045 gsl_function_wrapper(); 00046 00047 static point x; 00048 static size_t index; 00049 static realfunc myfunc; 00050 00051 static gsl_function* f; 00052 }; 00053 } 00054 00055 #endif //__FUNC_H__