Computational Physics - Department of Physics

(Axel Boer) #1

146 5 Numerical Integration


/**
*@brief Evaluate the integral.
*@return The value of the integral in double precision.
**/
virtual doubleevaluate()=0;

// virtual forloop

};// End class Integral


classTrapezoidal:publicIntegral{
private:
doubleh; // Step size.
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.
    **/
    Trapezoidal(doublelower
    ,doubleupper,intnpts, Function &f_);
    //! Destructor
    ~Trapezoidal(){}
    /**
    Evaluate the integral of a function f using the trapezoidal rule.
    *@return The value of the integral in double precision.
    **/
    doubleevaluate();
    };// End class Trapezoidal


classMidPoint:publicIntegral{
private:
doubleh; // Step size.
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.
    **/
    MidPoint(doublelower
    ,doubleupper,intnpts, Function &f_);
    //! Destructor
    ~MidPoint(){}
    /**
    Evaluate the integral of a function f using the midpoint approximation.


  • *@return The value of the integral in double precision.
    **/
    doubleevaluate();



Free download pdf