Function Repository Resource:

NewtonCotesWeights

Source Notebook

Get the abscissa-weight pairs of the elementary Newton-Cotes formula

Contributed by: Jan Mangaldan

ResourceFunction["NewtonCotesWeights"][n,a,b]

gives a list of the n pairs {xi,wi} of the elementary n-point Newton-Cotes formula for quadrature on the interval a to b, where wi is the weight of the abscissa xi.

Details and Options

Newton-Cotes quadrature approximates the value of an integral as a linear combination of values of the integrand evaluated at equally spaced points: .
The abscissas may or may not include the endpoints a and b of the interval. The option "QuadratureType" is used to control whether endpoints are included as abscissas.
With the default setting "QuadratureType"Closed, the endpoints are included as abscissas.
With the setting "QuadratureType"Open, the endpoints are not included as abscissas. In this case, the initial abscissa is chosen to be a half step above the lower endpoint and the final is a half step below the upper endpoint.

Examples

Basic Examples (1) 

Find the Newton-Cotes value weight:

In[1]:=
ResourceFunction["NewtonCotesWeights"][10, 0, 9]
Out[1]=

Options (1) 

Set "QuadratureType"Open to exclude the endpoints:

In[2]:=
ResourceFunction["NewtonCotesWeights"][10, 0, 9, "QuadratureType" -> Open]
Out[2]=

Applications (5) 

Approximate the area below a curve f(x)

Define the function:

In[3]:=
f[x_] := x^3 - 5 x^2 + 3 x + 9

Visualize the area between 0 and 5:

In[4]:=
Plot[f[x], {x, 0, 5}, Filling -> Axis]
Out[4]=

Determine the Newton-Cotes weights:

In[5]:=
weights = ResourceFunction["NewtonCotesWeights"][6, 0, 5]
Out[5]=

Multiply the value at each x-value by its weight:

In[6]:=
Total[#[[2]]*f[#[[1]]] & /@ weights] // N
Out[6]=

Compare to the solution of NIntegrate:

In[7]:=
NIntegrate[f[x], {x, 0, 5}]
Out[7]=

Properties and Relations (1) 

The resource function NewtonCotesError can be used to determine the error in the Newton–Cotes approximation:

In[8]:=
ResourceFunction["NewtonCotesError"][6, f, 0, 5]
Out[8]=

Version History

  • 1.1.0 – 04 January 2021
  • 1.0.0 – 20 November 2019

Source Metadata

Related Resources

License Information