You are here: Symbol Reference > MtxIntDiff Namespace > Functions > MtxIntDiff.WeightsNewtonCotes Function
MtxVec VCL
ContentsIndex
PreviousUpNext
MtxIntDiff.WeightsNewtonCotes Function

Newton-Cotes base points and weights.

Pascal
procedure WeightsNewtonCotes(PolyOrder: Integer; const Points: TVec; const Weights: TVec; const FloatPrecision: TMtxFloatPrecision = mvDouble);
Parameters 
Description 
PolyOrder 
Defines the interpolating polynomial order. 
Points 
Returns base points coordinate. 
Weights 
Returns weights. 
FloatPrecision 
Specifies the precision of the weights to be returned. 

Uses the Newton-Cotes formulas to calculate base points and weights for numerical integration. Check the following linkto learn more about Newton-Cotes formulas.

Use Simpson rule to evaluate sin(x) on interval [0,PI].

// Integrating function function IntFunc(const Parameters: TVec; const Constants: TVec; const ObjConst: Array of TObject): double; var x: double; begin x := Parameters[0]; IntFunc := Sin(x); end; // Integrate procedure DoIntegrate; var bpoints,weights: Vector; area: double; begin WeightsNewtonCotes(2,bpoints,weights); // 2 means Simpson area := QuadGauss(IntFunc,0,PI,bpoints,weights,1); end;
#include "MtxExpr.hpp" #include "Math387.hpp" #include "MtxIntDiff.hpp" // Integrating function double __fastcall IntFun(TVec* const Parameters, TVec* const Constants, 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); }
Examples on GitHub
Copyright (c) 1999-2025 by Dew Research. All rights reserved.
What do you think about this topic? Send feedback!