tmontecarlo.h - numeric - C++ library with numerical algorithms
 (HTM) git clone git://src.adamsgaard.dk/numeric
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
       tmontecarlo.h (1065B)
       ---
            1 #ifndef MONTECARLO_H_
            2 #define MONTECARLO_H_
            3 
            4 #include <vector>
            5 #include "header.h"
            6 
            7 class MC {
            8 
            9   private:
           10 
           11     // Length of vectors
           12     const Lengthtype d;
           13 
           14     // Function to be evaluated (pointer to function)
           15     Floattype (*f)(const std::vector<Floattype>);
           16 
           17     // Integral limits in dimension d
           18     const std::vector<Floattype> a;
           19     const std::vector<Floattype> b;
           20 
           21     // n-dimensional point
           22     std::vector<Floattype> x;
           23 
           24     // Number of samples
           25     const Lengthtype N;
           26 
           27     // Integration result
           28     Floattype Q;
           29 
           30     // Error
           31     Floattype err;
           32 
           33     // Volume
           34     Floattype V;
           35     void set_volume();
           36 
           37     // Draw random position in sample space
           38     std::vector<Floattype> random_x();
           39 
           40   public:
           41 
           42     // Constructor
           43     MC(Floattype (*function)(const std::vector<Floattype>),
           44        const std::vector<Floattype> a_in,
           45        const std::vector<Floattype> b_in,
           46        const Lengthtype N_in);
           47 
           48     // Plain Monte Carlo integrator
           49     void plain();
           50 
           51     // Print result and error
           52     void show();
           53 
           54     // Return the error
           55     Floattype error();
           56 };
           57 
           58 #endif