next up previous contents index
Next: Fourier transform (FFT) Up: Module NTools Previous: Polynomial   Contents   Index


Integration, Differential equations

The NTools module provide also simple classes for numerical integration of functions and differential equations.

\begin{figure}
\framebox [40mm][c]{\mbox{\rule[-1mm]{0mm}{5mm} \bf PPersist} }\...
...ebox [40mm][c]{\mbox{\rule[-1mm]{0mm}{5mm} \bf TrpzInteg} }\\ [2mm]
\end{figure}

GLInteg implements the integration through Gauss-Legendre method and TrpzInteg implements trapeze integration. For TrpzInteg, number of steps specify the number of trapeze, and integration step, their width. The sample code below illustrates the use of TrpzInteg class:


#include "integ.h"
// ......................................................
// Function to be integrated
double myf(double x)
{
// Simple a x + b x^2  (a=2 b=3)
return (x*(2.+3.*x));
}
// ......................................................

// Compute Integral(myf, 2., 5.) between xmin=2., xmax=5.
TrpzInteg trpz(myf, 2., 5.);
// We specify an integration step
trpz.DX(0.01);
// The integral can be computed as trpz.Value() 
double myf_integral = trpz.Value();
// We could have used the cast operator :
cout << "Integral[myf, 2., 5.]= " << (double)trpz << endl;
// Limits can be specified through ValueBetween() method 
cout << "Integral[myf, 0., 4.]= " << trpz.ValueBetween(0.,4.) << endl;



Reza Ansari
2001-03-07