Dew MtxVec NET
QuadGauss Routines
Summary
Numerical integration by using regular Gaussian quadrature scheme.

Unit
MtxIntDiff

Declaration
Function QuadGauss(Fun: TRealFunction; lb, ub: TSample; const Constants: array of TSample; const ObjConst: array of TObject; BasePoints, Weights: TVec; Parts: Integer): TSample;


Declaration
Function QuadGauss(Fun: TRealFunction; lb, ub: TSample; const Constants: array of TSample; const ObjConst: array of TObject; out StopReason: TIntStopReason; QMethod: TQuadMethod = qmGauss; Tolerance: TSample = 1.0E-4; MaxIter: Integer = 8): TSample;

Description
Evaluate the numerical integral between lower and upper bound using Gauss quadrature algorithm. This version calculates base points and weights on the fly.
 See Also 
Romberg 

Example 1

Evaluate fuction Sin(x)*Exp(-x^2) on interval -Pi/2, PI. Use default Gauss base points and weights.
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 := QuadGauss(IntFunc,-0.5*PI,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 = QuadGauss(IntFun,0.0,5*PI,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.QuadGauss(IntFun,-0.5*System.Math.PI,out sr, 1.0e-4, 8); }


Declaration
Function QuadGauss(Fun: TRealFunction; lb, ub: TSample; out StopReason: TIntStopReason; QMethod: TQuadMethod = qmGauss; Tolerance: TSample = 1.0E-4; MaxIter: Integer = 8): TSample;


Declaration
Function QuadGauss(Fun: TRealFunction; lb, ub: TSample; BasePoints, Weights: TVec; Parts: Integer): TSample;
Result
the numerical approximate on integral of function Fun between limits lb and ub. Check the following
link to learn more about Gauss Quadrature algorithm.
 See Also 
Romberg 
WeightsGauss 
WeightsNewtonCotes 
WeightsChebyshevGauss 

Example 1

Evaluate fuction Sin(x)*Exp(-x^2) on interval -Pi/2, PI.
Uses MtxExpr, 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 bpoints,weights: Vector; area: TSample; begin WeightsGauss(10,bpoints,weights); area := QuadGauss(IntFunc,-0.5*PI,PI,bpoints,weights,64); 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(); { Vector bpoints, weights; WeightsGauss(10,bpoints,weights); double area = QuadGauss(IntFun,-0.5*PI,PI,bpoints,weights,64); }
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() { Vector bpoints = new Vector(0); Vector weights = new Vector(0); MtxIntDiff.WeightsGauss(10,bpoints,weights); double area = MtxIntDif.QuadGauss(IntFun,-0.5*System.Math.PI,System.Math.PI,bpoints,weights,64); }

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