User:John Randall/Quadrature

From J Wiki
Jump to: navigation, search

Let be a continuous function on . Let be an integer, , , . Then we can estimate as the linear combination for some choice of coefficients .

In the case we have, for example Our aim is to explain where the magic coefficients come from.

Suppose the points are divided into contiguous panes, each with points, so that . For the trapezoidal rule, we have , , and for Simpson's rule we have , . Consider a single pane with points, and suppose , , . The general result will follow from the linearity properties of the integral. Let be the Lagrange basis polynomials of degree satisfying for . Then

require 'numeric'
V=:^/~ @: i.@:#
L=:clean@(%. V)"1
basis=:L @: =@i.@>:
int=:(0&p.. p. <:@:#)"1
c=:int@basis
   c 1
0.5 0.5
   c 2
0.333333 1.33333 0.333333

For a single pane, these give

The result for multiple panes is simple additivity of the single pane result:

tz=:#~ -.@(*./\.)@(0&=)  NB. remove trailing zeros
ppr=:+//.@(*/)           NB. polynomial product
pprtz=:tz@:ppr
coeff=:(c@:]) pprtz 0 = ] | i.@:*
   6 coeff 1
0.5 1 1 1 1 1 0.5
   3 coeff 2
0.333333 1.33333 0.666667 1.33333 0.666667 1.33333 0.333333

The same method works for generating formulas with more interpolating points (although there are good reasons for stopping at Simpson's rule). If we take , we get:

   2 coeff 3
0.375 1.125 1.125 0.75 1.125 1.125 0.375