Dew MtxVec NET
WeightsNewtonCotes Routine
Summary
Newton-Cotes base points and weights.

Unit
MtxIntDiff

Declaration
Procedure WeightsNewtonCotes(PolyOrder: Integer; Points, Weights: TVec);
 Parameter  Description 
PolyOrder Defines the interpolating polynomial order. 
Points Returns base points coordinate. 
Weights Retursn weights. Check the following link to learn more about Newton-Cotes formulas. 

Description
Uses the Newton-Cotes formulas to calculate base points and weights for numerical integration.
 See Also 
WeightsChebyshevGauss 
WeightsGauss 

Example 1

Use Simpson rule to evaluate sin(x) on interval [0,PI].
// 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); end; // Integrate procedure DoIntegrate; var bpoints,weights: Vector; area: TSample; begin WeightsNewtonCotes(2,bpoints,weights); // 2<--Simpson area := QuadGauss(IntFunc,0,PI,bpoints,weights,1); 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; WeightsNewtonCotes(2,bpoints,weights); double area = QuadGauss(IntFun,-0.5*PI,PI,bpoints,weights,1); }
// Integrating function private double IntFunc(TVec Parameters, double[] c, object[] o) { double x = Parameters[0]; return System.Math.Sin(x); } // Integrate private void DoIntegrate() { Vector bpoints = new Vector(0); Vector weights = new Vector(0); MtxIntDiff.WeightsNewtonCotes(2,bpoints,weights); // 2<--Simpson double area = QuadGauss(IntFunc,0,System.Math.PI,bpoints,weights,1); }

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