5.6 An Integration Class 145
#ifndefFUNCTION_H
#defineFUNCTION_H
#include"Array.h"
classFunction{
public:
//! Destructor
virtual~Function(){};// Not needed here.
/*
@brief Overload the function operator().
- *Used for evaluating functions with one independent variable.
/
virtual double operator()(doublex){}
/
*@brief Overload the function operator().
*Used for evaluating functions with more than one independent variable.
**/
virtual double operator()(constArray& x){}
};
#endif
The header fileIntegral.hcontains, with an example on how to use it, the following state-
ments
http://folk.uio.no/mhjensen/compphys/programs/chapter05/cpp/Integral.h
#ifndefINTEGRAL_H
#defineINTEGRAL_H
#include"Array.h"
#include"Function.h"
#include
classIntegral{
protected: // Access in the subclasses.
doublea; // Lower limit of integration.
doubleb; // Upper limit of integration.
intnpts; // Number of integration points.
Function &f;// Function to be integrated.
public:
/*
@brief Constructor.
- @param lower_. Lower limit of integration.
@param upper. Upper limit of integration.
*@param npts. Number of points of integration.
*@param f. Reference to a functor representing the function to be integrated.
**/
Integral(doublelower,doubleupper,intnpts, Function &f_);
//! Destructor
virtual~Integral(){}