cotes.RdClosed composite Newton-Cotes formulas of degree 2 to 8.
cotes(f, a, b, n, nodes, ...)2 to 8 point closed and summed Newton-Cotes numerical integration formulas.
These formulas are called `closed' as they include the endpoints. They are called `composite' insofar as they are combined with a Lagrange interpolation over subintervals.
The integral as a scalar.
It is generally recommended not to apply Newton-Cotes formula of degrees
higher than 6, instead increase the number n of subintervals used.
Quarteroni, A., R. Sacco, and F. Saleri (2007). Numerical Mathematics. Second Edition, Springer-Verlag, Berlin Heidelberg.
cotes(sin, 0, pi/2, 20, 2) # 0.999485905248533
#> [1] 0.9994859
cotes(sin, 0, pi/2, 20, 3) # 1.000000211546591
#> [1] 1
cotes(sin, 0, pi/2, 20, 4) # 1.000000391824184
#> [1] 1
cotes(sin, 0, pi/2, 20, 5) # 0.999999999501637
#> [1] 1
cotes(sin, 0, pi/2, 20, 6) # 0.999999998927507
#> [1] 1
cotes(sin, 0, pi/2, 20, 7) # 1.000000000000363 odd degree is better
#> [1] 1
cotes(sin, 0, pi/2, 20, 8) # 1.000000000002231
#> [1] 1