Dew MtxVec NET
Romberg Routine
Summary
Numerical integration by using recursive Romberg algorithm.

Unit
MtxIntDiff

Declaration
Function Romberg(Fun: TRealFunction; lb, ub: TSample; const Constants: array of TSample; const ObjConst: array of TObject; out StopReason: TIntStopReason; Tolerance: TSample = 1.0e-4; MaxIter: Integer = 100): TSample;

 See Also 
QuadGauss 

Example 1

Evaluate fuction Sin(x)*Exp(-x^2) on interval [0,PI/2] by using Romberg algorithm.
Uses Math387, MtxIntDiff; // Integrating function function IntFunc(Parameters: TVec; Const Constants: Array of TSample; Const ObjConst: Array of TObject): TSample; var x: TSample; begin x := Parameters[0]; Result := Sin(x)*Exp(-x*x); end; // Integrate procedure DoIntegrate; var area: TSample; sr: TIntStopReason; begin area := Romberg(IntFunc,0,0.5*PI,sr); end;
#include "MtxVecCpp.h" #include "Math387.hpp" #include "MtxIntDiff.hpp" // Integrating function double __fastcall IntFun(TVec * Parameters, const double * Constants, const int Constants_Size, System::TObject* const * ObjConst, const int ObjConst_Size) { double x = (*Parameters)[0]; return Math.Sin(x)*Math.Exp(-x*x); } void __fastcall Example(); { TIntStopReason sr; double area = Romberg(IntFun,0.0,5*PI,NULL,NULL,sr); }
private double IntFun(TVec x, double[] c, object[] o) { double x = x[0]; return System.Math.Sin(x)*System.Math.Exp(-x*x); } private void Example() { TIntStopReason sr; double area = MtxIntDif.Romberg(IntFun,0.0,5*System.Math.PI,out sr, 1.0e-4, 100); }

Copyright 2008 Dew Research
http://www.dewresearch.com