ma/cs 375 fall 20021 ma/cs 375 fall 2002 lecture 32

Post on 21-Dec-2015

213 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

MA/CS 375 Fall 2002 1

MA/CS 375

Fall 2002

Lecture 32

MA/CS 375 Fall 2002 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 Newton’s method.

Review

MA/CS 375 Fall 2002 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

kk k i k

kk

i k i

k

x

f xx x

df xf x

dx x x

x

Review

MA/CS 375 Fall 2002 4

Mul

tiple

Roo

t Fin

der

(app

lied

to fi

nd

ro

ots

of L

ege

ndre

po

lyn

om

ials

)

Should read abs(delta) > tol

Review + Correction

MA/CS 375 Fall 2002 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 if mx x dx n m

Review

MA/CS 375 Fall 2002 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 x

n n

Review

MA/CS 375 Fall 2002 7

Roots of the 10th Order Legendre Polynomial

Notice how they cluster at the end points

Review

MA/CS 375 Fall 2002 8

Numerical Quadrature

• A numerical quadrature is a set of two vectors.

• The first vector is a list of x-coordinates for nodes where a function is to be evaluated.

• The second vector is a set of integration weights, used to calculate the integral of a function which is given at the nodes

MA/CS 375 Fall 2002 9

Example of Quadrature

• Say we wish to calculate an approximation to the 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,..,wN so that:

1

1

f x dx

1

11

i N

i ii

f x dx w f x

MA/CS 375 Fall 2002 10

Example: Simpson’s RuleRecall:

• 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.

MA/CS 375 Fall 2002 11

Example: Simpson’s 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 2

1

weights , , , , ,

2,

3 1

8, , , ,

3 1

4, , , ,

3 1

N

n

N

N

N

x x x x x

nx

N

w w w w w

w wN

w w w wN

w w w wN

quadrature:

MA/CS 375 Fall 2002 12

Example: Simpson’s 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 nn

f x dx w f x

MA/CS 375 Fall 2002 13

Newton-Cotes Formula

• The next approach we are going to use is the well known Newton-Cotes quadrature.

• Suppose we are given a set of points x1,x2,..,xN. Then we require that the constant is exactly integrated:

11 10 0 0 0

1 1 2 2

1 11N N

xw x w x w x x dx

MA/CS 375 Fall 2002 14

11 10 0 0 0

1 1 2 2

1 1

11 21 1 1 1

1 1 2 2

1 1

111 1 1 1

1 1 2 2

1 1

1

2

N N

N N

NN 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

MA/CS 375 Fall 2002 15

11

0 0 011 2 22

1 1 121 2

1 1 11 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?

MA/CS 375 Fall 2002 16

11

0 0 011 2 22

1 1 121 2

1 1 11 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

tV w

It’s the transpose of the Vandermonde matrix

MA/CS 375 Fall 2002 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 of the area under f

• Clearly, we can estimate the approximation error using the estimates for the error in the interpolation we used before.

MA/CS 375 Fall 2002 18

Newton-Cotes Weights

11

1 22

2

1 1

1

1 1

2

1 1

t

N NN

w

w

w

N

1V

MA/CS 375 Fall 2002 19

Using Newton-Cotes Weights

1

11

i Nt

i ii

f x dx w f x

w f

MA/CS 375 Fall 2002 20

Using Newton-Cotes Weights(Interpretation)

1

11

1 21 21 1 1 1 1 1

1 2

i Nt

i ii

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.

MA/CS 375 Fall 2002 21

Matlab Function for Calculating Newton-Cotes Weights

MA/CS 375 Fall 2002 22

Demo: Matlab Function for Calculating Newton-Cotes Weights

1) set N=5 points2) build equispaced nodes3) calculate NC weights

4) evaluate F=X^3 at nodes5) evaluate integral

6) F is anti-symmetric on [-1,1] so its integral is 0

7) Answer correct

MA/CS 375 Fall 2002 23

Individual Exercise

• Download the contents of:http://www.math.unm.edu/~timwar/MA375F02/Integration

• make sure your matlab path points to your copy of this directory

• using a script figure out what order polynomial the weights produced with newtoncotes can exactly integrate for a given set of N points (say N=3,4,5,6,7,8) created with linspace

MA/CS 375 Fall 2002 24

Gauss Quadrature

• The construction of the Newton-Cotes weights does not utilize 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 be integrated exactly using just N points.

MA/CS 375 Fall 2002 25

2 1

1

where:

f 1,1

where 1,1

0 where s 1,1

1,1

p

pi i

pi

p

f x If x r x s x

If x f x If

s x

r

P

P

P

P

Suppose:

MA/CS 375 Fall 2002 26

2 1

1

where:

f 1,1

where 1,1

0 where s 1,1

1,1

p

pi i

pi

p

f x If x r x s x

If x f x If

s x

r

P

P

P

P

Suppose:Remainder term, whichmust have p roots locatedat the interpolating nodes

MA/CS 375 Fall 2002 27

1 1 1

1 1 1

1

1 1

i N

i ii

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!.

Let’s integrate this formula for f over [-1,1]

MA/CS 375 Fall 2002 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

MA/CS 375 Fall 2002 29

1

2 1

11

for all i N

Ni 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:

MA/CS 375 Fall 2002 30

Summary of Gauss Quadrature

• We can use the multiple root finder to locate the roots of the N’th order Legendre polynomial.

• We can then use the Newton-Cotes formula with the roots of the N’th order Legendre polynomial to calculate a set of N weights.

• We now have a quadrature !!! which will integrate polynomials of order 2N-1 with N points

MA/CS 375 Fall 2002 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 both functions on the same graph.

top related