newton cotes method
TRANSCRIPT
-
8/14/2019 Newton Cotes method
1/31
1
Newton Cotes Method
-
8/14/2019 Newton Cotes method
2/31
2
Roots of a Polynomial
Suppose we wish to find all the roots of a
polynomial of order P
Then there are going to be at most P roots!.
We can use a variant of Newtons method.
Review
-
8/14/2019 Newton Cotes method
3/31
3
Newton Scheme For Multiple
Root Finding
1 2 P
1
1
Initiate guesses to the roots ,x ,..x
Loop over k=1:P
Iterate:
1
to find to a given tolerance
End loop
k
k ki k
k
k
i k i
k
x
f xx x
df xf x
dx x xx
Review
-
8/14/2019 Newton Cotes method
4/31
4
MultipleRo
otFinder
(appliedto
findrootsofL
egendrepolyn
omials)
Should read abs(delta) > tol
Review + Correct ion
-
8/14/2019 Newton Cotes method
5/31
5
Legendre Polynomials
Legendre polynomials are a special set
of polynomials which are orthogonal in
the L2 inner product:
1
n
1
L L 0 ifmx x dx n m
Review
-
8/14/2019 Newton Cotes method
6/31
6
Legendre Polynomials
Legendre polynomials can be calculate
using the following recursion relation:
0
1
n 1 n n 1
L 1
L
2 1L L L n=1,2,...1 1
x
x x
n nx x x xn n
Review
-
8/14/2019 Newton Cotes method
7/31
7
Roots of the 10thOrder
Legendre Polynomial
Notice how they cluster at the end points
Review
-
8/14/2019 Newton Cotes method
8/31
8
Numerical Quadrature
A numerical quadrature is a set of two vectors.
The first vector is a list of x-coordinates fornodes where a function is to be evaluated.
The second vector is a set of integrationweights, used to calculate the integral of a
function which is given at the nodes
-
8/14/2019 Newton Cotes method
9/31
9
Example of Quadrature
Say we wish to calculate an approximation tothe integral of f over [-1,1] :
Suppose we know the value of f at a set of N
points then we would like to find a set of
weights w1,w2,..,wNso that:
1
1
f x dx
1
11
i N
i i
i
f x dx w f x
-
8/14/2019 Newton Cotes method
10/31
10
Example: Simpsons Rule
Recall:
The idea is to sample a function at N points. Then using a shifting stencil of 3 points construct
a quadratic interpolant through those 3 points.
Then integrate the area under the interpolant in
the range bracketed by the three points.
Sum up all the contributions from the sets of
three points.
-
8/14/2019 Newton Cotes method
11/31
11
Example: Simpsons Rule
1
1
1 2 3 4
2 4 2 4 ...
3( 1) N
f x dx
f x f x f x f x f xN
1 2 3 4
1 1 1 1 1
1
2 4 6 1
3 5 7 2
nodes { , , , , , }
11 21
weights , , , , ,
2,
3 18
, , , ,3 1
4, , , ,
3 1
N
n
N
N
N
x x x x x
nxN
w w w w w
w w
N
w w w wN
w w w wN
quadrature:
-
8/14/2019 Newton Cotes method
12/31
12
Example: Simpsons Rule
1
1
1 2 3 4
2 4 2 4 ...
3( 1) N
f x dx
f x f x f x f x f xN
becomes:
1
1 1 2 2 3 3
1
.. N Nf x dx w f x w f x w f x w f x
in summation notation:
1
11
n N
n n
n
f x dx w f x
-
8/14/2019 Newton Cotes method
13/31
13
Newton-Cotes Formula
The next approach we are going to use is thewell known Newton-Cotes quadrature.
Suppose we are given a set of pointsx1,x2,..,xN. Then we require that the constant
is exactly integrated:
11 10 0 0 0
1 1 2 2
1 11
N N
xw x w x w x x dx
-
8/14/2019 Newton Cotes method
14/31
14
11 10 0 0 0
1 1 2 2
1 1
1
1 21 1 1 1
1 1 2 2
1 1
11
1 1 1 1
1 1 2 2
1 1
1
2
N N
N N
N
N N N N
N N
xw x w x w x x dx
xw x w x w x x dx
xw x w x w x x dx
N
Now we require that 1,x,x2,..,xN-1
are integrated exactly
-
8/14/2019 Newton Cotes method
15/31
15
11
0 0 011 2 22
1 1 1
21 2
1 1 1
1 2
1 1
1
1 1
2
1 1
N
N
N N NNN NN
wx x x
wx x x
wx x x
N
In Matrix Notation:
Notice anything familiar?
-
8/14/2019 Newton Cotes method
16/31
16
11
0 0 0
11 2 221 1 1
21 2
1 1 11 2
1 1
1
1 1
2
1 1
N
N
N N N NN NN
wx x xwx x x
wx x x
N
tV w
Its the transpose of the
Vandermonde matrix
-
8/14/2019 Newton Cotes method
17/31
17
Integration by Interpolation
In essence this approach uses the unique
(N-1)th order interpolating polynomial If and
integrates the area under the If instead ofthe area under f
Clearly, we can estimate the approximationerror using the estimates for the error in the
interpolation we used before.
-
8/14/2019 Newton Cotes method
18/31
18
Newton-Cotes Weights
11
1 22
2
1 1
1
1 1
2
1 1
t
N NN
ww
w
N
1
V
-
8/14/2019 Newton Cotes method
19/31
19
Using Newton-Cotes Weights
1
11
i Nt
i i
i
f x dx w f x
w f
-
8/14/2019 Newton Cotes method
20/31
20
Using Newton-Cotes Weights
(Interpretation)
1
11
1 21 21 1 1 1 1 1
1 2
i Nt
i i
i
NN
f x dx w f x
N
1
w f
V f
i.e. we calculate the coefficients of the interpolating polynomial
expansion using the Vandermonde, then since we know the
integral of each term we can sum up the integral of each term
to get the total.
-
8/14/2019 Newton Cotes method
21/31
21
Matlab Function for Calculating
Newton-Cotes Weights
-
8/14/2019 Newton Cotes method
22/31
22
Demo: Matlab Function for
Calculating Newton-Cotes Weights
1) set N=5 points
2) build equispaced nodes
3) calculate NC weights
4) evaluate F=X^3 at nodes
5) evaluate integral
6) F is anti-symmetric on
[-1,1] so its integral is 0
7) Answer correct
-
8/14/2019 Newton Cotes method
23/31
23
Individual Exercise
Download the contents of:http://www.math.unm.edu/~timwar/MA375F02/Integration
make sure your matlab path points to your copy ofthis directory
using a script figure out what order polynomial the
weights produced with newtoncotes can exactlyintegrate for a given set of N points (say
N=3,4,5,6,7,8) created with l inspace
-
8/14/2019 Newton Cotes method
24/31
24
Gauss Quadrature
The construction of the Newton-Cotes
weights does no tutilize the ability to choose
the distribution of nodes for greater accuracy.
We can in fact choose the set of nodes to
increase the order of polynomial that can beintegrated exactly using just N points.
-
8/14/2019 Newton Cotes method
25/31
25
2 1
1
where:
f 1,1
where 1,1
0 where s 1,1
1,1
p
p
i i
p
i
p
f x If x r x s x
If x f x If
s x
r
P
P
P
P
Suppose:
Remainder term which
-
8/14/2019 Newton Cotes method
26/31
26
2 1
1
where:
f 1,1
where 1,1
0 where s 1,1
1,1
p
p
i i
p
i
p
f x If x r x s x
If x f x If
s x
r
P
P
P
P
Suppose:Remainder term, which
must have p roots located
at the interpolating nodes
-
8/14/2019 Newton Cotes method
27/31
27
1 1 1
1 1 1
1
1 1
i N
i i
i
f x If x r x s x
f x dx If x dx r x s x dx
w f x r x s x dx
At this point we can choose the nodes {xi}.
If we choose them so that they are the p+1 roots of
the (p+1)th order Legendre function then s(x) is in
fact the N=(p+1)th order Legendre function itself!.
Lets integrate this formula for f over [-1,1]
-
8/14/2019 Newton Cotes method
28/31
28
1 1 1
1 1 1
1 1
1 1
1
1 1
N
i N
i i Ni
f x dx If x dx s x r x dx
If x dx L x r x dx
w f x L x r x dx
But we also know that if r is a lower order polynomial than
(p+1)th order, it can be expressed as a linear combination
of Legendre polynomials {L1, L2, L3, , LN}.
By the orthogonality of the Legendre polynomials we know
that the s is in fact orthogonal to Lp+1
-
8/14/2019 Newton Cotes method
29/31
29
1
2 1
11
for alli N
N
i i
i
f x dx w f x f
P
i.e. the quadrature is exact for all polynomials
of order up to p=(2N-1)
Hence:
-
8/14/2019 Newton Cotes method
30/31
30
Summary of Gauss Quadrature
We can use the multiple root finder to locate theroots of the Nth order Legendre polynomial.
We can then use the Newton-Cotes formulawith the roots of the Nth order Legendrepolynomial to calculate a set of N weights.
We now have a quadrature !!! which willintegrate polynomials of order 2N-1 with Npoints
-
8/14/2019 Newton Cotes method
31/31
31
Team Exercise
Use the root finder (gaussNR) and Newton-Cotes routines(newtoncotes) to build a quadrature for N points (N arbitrary).
Use it to integrate exp(x) over the interval [-1,1]
Use it to integrate 1./(1+25*x.^2) over the interval [-1,1]
For N=2,3,4,5,6,7,8,9 plot the integration error for bothfunctions on the same graph.