#include <crombergintegrator.h>
Public Member Functions | |
CRombergIntegrator () | |
CRombergIntegrator (double(*function)(double)) | |
CRombergIntegrator (double eps, int jmax, int k, double(*function)(double)) | |
CRombergIntegrator (void *, double(*function)(void *, double)) | |
CRombergIntegrator (double eps, int jmax, int k, void *, double(*function)(void *, double)) | |
~CRombergIntegrator () | |
double | compute (double a, double b) |
Protected Member Functions | |
double | function (double) |
void | polint (double xa[], double ya[], int n, double x, double *y, double *dy) |
double | trapzd (double a, double b, int n) |
Protected Attributes | |
double(* | function_class )(void *, double) |
void * | callingClass |
double(* | function_fun )(double) |
RI_CallMethod | mCallMethod |
double * | s |
double * | h |
int | jmax |
int | k |
double | eps |
This is an implementation of the Romberg integrator from the book numerical recipes. It will integrate functions of type double with a single double argument. The default integration parameters are in the header file, but they can easily be changed with the alternate constructor.
Definition at line 18 of file crombergintegrator.h.
CRombergIntegrator::CRombergIntegrator | ( | ) |
The default constructor is just here to make sure that the destructor doesn't destroy memory with a delete of the internal arrays. This is done by initalizing the arrays to null.
Definition at line 18 of file crombergintegrator.cc.
CRombergIntegrator::CRombergIntegrator | ( | double(*)(double) | fun | ) |
This is the constructor to use if you just want to integrate a function, and trust that the default parameters of the Romberg integrator are good enough for you. In most cases this is a safe bet. If you plan to torure the integrator, you better learn how to use the constructor with varaible parameters.
Definition at line 26 of file crombergintegrator.cc.
CRombergIntegrator::CRombergIntegrator | ( | double | a_eps, | |
int | a_jmax, | |||
int | a_k, | |||
double(*)(double) | fun | |||
) |
This constructor allows you to fully tweek the integrator. You can only tweek the parameters at the construction of the object. I didn't feel the need to allow dynamic changing of the parameters. You can simply make another object with different paramerts. If this is a big problem for you let me know, and I will make it more fancy.
a_eps | The fractional accruacy desired. Be carefull, if you make this too small you will run into machine accuracy. | |
a_jmax | The maximum number of divisions the integration will make. For each increase of 1 in this parameter, the number of division in the function will double. | |
a_k | The order of the polynomial that is used in the estimation of the error in the integration. |
Definition at line 42 of file crombergintegrator.cc.
CRombergIntegrator::CRombergIntegrator | ( | void * | class_ptr, | |
double(*)(void *, double) | fun | |||
) |
These next two functions solve the problem when you want to call this integrator from a non static member function. The problem is that if you send a pointer to the member function that you want to integrate, the compiler will complain since the "this" pointer has to be sent also. The extra argument allows for this. You also have to set up a static member in your calling class to pass to this function. That way this class doesn't have to know anything about the class that is using it. If you want more information on why this is nessasary, the problem is called "callback" and you can look it up in any good c++ book, or look on the web.
Definition at line 55 of file crombergintegrator.cc.
CRombergIntegrator::CRombergIntegrator | ( | double | eps, | |
int | jmax, | |||
int | k, | |||
void * | class_ptr, | |||
double(*)(void *, double) | function | |||
) |
Definition at line 67 of file crombergintegrator.cc.
CRombergIntegrator::~CRombergIntegrator | ( | ) |
Kill it and all of its memory!!
Definition at line 96 of file crombergintegrator.cc.
double CRombergIntegrator::compute | ( | double | a, | |
double | b | |||
) |
Once you create the object, you have to tell it to compute the integral. This function will compute the integral and return the result. You can call this multiple times for a given function without reseting anything.
a | The start (lower limit) of the integral | |
b | The end (upper limit) of the integral |
Definition at line 107 of file crombergintegrator.cc.
double CRombergIntegrator::function | ( | double | x | ) | [protected] |
Definition at line 79 of file crombergintegrator.cc.
void CRombergIntegrator::polint | ( | double | xa[], | |
double | ya[], | |||
int | n, | |||
double | x, | |||
double * | y, | |||
double * | dy | |||
) | [protected] |
Definition at line 124 of file crombergintegrator.cc.
double CRombergIntegrator::trapzd | ( | double | a, | |
double | b, | |||
int | n | |||
) | [protected] |
Definition at line 165 of file crombergintegrator.cc.
void* CRombergIntegrator::callingClass [protected] |
Definition at line 33 of file crombergintegrator.h.
double CRombergIntegrator::eps [protected] |
Definition at line 42 of file crombergintegrator.h.
double(* CRombergIntegrator::function_class)(void *, double) [protected] |
double(* CRombergIntegrator::function_fun)(double) [protected] |
double* CRombergIntegrator::h [protected] |
Definition at line 39 of file crombergintegrator.h.
int CRombergIntegrator::jmax [protected] |
Definition at line 40 of file crombergintegrator.h.
int CRombergIntegrator::k [protected] |
Definition at line 41 of file crombergintegrator.h.
RI_CallMethod CRombergIntegrator::mCallMethod [protected] |
Definition at line 35 of file crombergintegrator.h.
double* CRombergIntegrator::s [protected] |
Definition at line 38 of file crombergintegrator.h.