1 #ifndef QNANO_NEW_REAL_FUNCTION_DEFINED_H 2 #define QNANO_NEW_REAL_FUNCTION_DEFINED_H 13 virtual T
fct(
double x)=0;
21 virtual void plot(
const std::string &filename,
double xbegin,
double xend,
size_t Nintervals){
22 std::ofstream ofs(filename.c_str());
23 double h=(xend-xbegin)/(Nintervals);
24 for(
size_t i=0; i<Nintervals+1; i++){
26 ofs<<x<<
" "<<
fct(x)<<std::endl;
35 public:
double fct(
double x){
return 0.;}
39 public:
double fct(
double x){
return x;}
40 } Real_Function_Identity;
50 inline size_t size()
const{
53 void resize(
size_t newsz){
59 for(
size_t i=0; i<sz; i++)d[i]=0;
61 double access_check(
size_t i){
62 if(i<0){std::cerr<<
"Error accessing Multivar: i<0"<<std::endl; exit(1);}
63 if(i>=sz){std::cerr<<
"Error accessing Multivar: i>="<<sz<<std::endl; exit(1);}
72 double &operator[](
size_t i){
75 double operator[](
size_t i)
const{
80 inline void add(
const Multivar &other){
81 for(
size_t i=0; i<sz; i++)d[i]+=other.d[i];
83 inline void subtract(
const Multivar &other){
84 for(
size_t i=0; i<sz; i++)d[i]-=other.d[i];
86 inline void add_scaled(
double scale,
const Multivar &other){
87 for(
size_t i=0; i<sz; i++)d[i]+=scale*other.d[i];
89 inline void scale(
double scale){
90 for(
size_t i=0; i<sz; i++)d[i]*=scale;
95 for(
size_t i=0; i<sz; i++)d[i]=other.d[i];
115 template <
typename T>
132 template <
typename T>
142 mv.add_scaled(x, mv_dir);
143 return mvfct->
fct(mv);
153 template <
typename T>
162 return mvfct->
fct(mv_ref);
T operator()(double x)
overload parenthesis operator
Definition: Real_Function.h:16
virtual T fct(double x)
actual fuction. To be defined in derived class
Definition: Real_Function.h:140
virtual T fct(double x)=0
actual fuction. To be defined in derived class
Class to store the arguments for multi-variable function.
Definition: Real_Function.h:45
virtual T fct(const Multivar &v)=0
actual fuction. To be defined in derived class
T operator()(const Multivar &v)
overload parenthesis operator
Definition: Real_Function.h:123
Definition: Real_Function.h:133
virtual void plot(const std::string &filename, double xbegin, double xend, size_t Nintervals)
Plots function to file: discretized form 'xbegin' to 'xend' on 'Nintervals'+1 sample points...
Definition: Real_Function.h:21
Definition: Real_Function.h:154
Template for function with multiple double variables.
Definition: Real_Function.h:116
Template for function of a single real variable.
Definition: Real_Function.h:10
virtual T fct(double x)
actual fuction. To be defined in derived class
Definition: Real_Function.h:160