Docsity

Numerical Computing S’09: Homework-6 Solutions for Quadrature Rules, Assignments of Mathematics

Toggle sidebar
bg1
Numerical Computing S’09 MATH/CSCI 4800-01
Homework-6 Solutions
Due in class on Monday April 6, 2009
1. (Pencil-and-paper)
(a) If a quadrature rule Qn(f) for an interval [a,b] is based on polynomial interpolation at n
equally spaced points in the interval, what is the degree of the highest-degree polynomial that
can be integrated exactly by this rule?
(b) How will your answer to part (a) above change if you are at liberty to choose the placement of
the npoints?
(c) What is a composite quadrature rule? Why is it preferred to a simple quadrature rule for numer-
ically computing a definite integral with high accuracy?
(d) Why is it important for all of the weights of a quadrature rule to be non-negative?
(a) The highest degree is n−1 for neven, nfor nodd.
(b) Placement of the nnodes adds an extra ndegrees of freedom, thereby increasing the degree of
the exactly integrable polynomial by n.
(c) A simple quadrature rule uses a high-degree polynomial interpolant to approximate the function
being integrated, thereby yielding an error term that depends upon a high-order derivative of the
integrand. A composite quadrature rule divides the interval of integration into a number of panels,
and applies a low-order rule on each. The error term then involves only a low-order derivative of
the integrand. For functions whose derivatives increase rapidly with the order of differentiation,
the composite rule is therefore more accurate.
(d) The condition number κfor an n-point quadrature rule for the integral Rb
af(x)dx is
κ=
n
X
i=1 |wi|,
where the wiare the weights. It is also known that
n
X
i=1
wi=b−a.
If the wiare all positive, then the above equations show that κis simply equal to b−a. If some
of the weights are negative, then
κ=
n
X
i=1 |wi|>
n
X
i=1
wi=b−a.
i.e., the algorithm is less well-conditioned.
2. (Pencil-and-paper and possibly Matlab) Suppose that you are using Simpson’s rule to approximate an
integral over the interval [a, b].If you wish to obtain a more accurate approximation of the integral,
which of the following will gain more accuracy?
(a) Dividing the interval in half and using Simpson’s rule on each subinterval.
(b) Using a closed Newton-Cotes rule with the same 5 points as nodes.
pf3
pf4
pf5

Partial preview of the text

Download Numerical Computing S’09: Homework-6 Solutions for Quadrature Rules and more Assignments Mathematics in PDF only on Docsity!

Numerical Computing S’09 MATH/CSCI 4800- Homework-6 Solutions

Due in class on Monday April 6, 2009

  1. (Pencil-and-paper)

(a) If a quadrature rule Qn(f ) for an interval [a, b] is based on polynomial interpolation at n equally spaced points in the interval, what is the degree of the highest-degree polynomial that can be integrated exactly by this rule? (b) How will your answer to part (a) above change if you are at liberty to choose the placement of the n points? (c) What is a composite quadrature rule? Why is it preferred to a simple quadrature rule for numer- ically computing a definite integral with high accuracy? (d) Why is it important for all of the weights of a quadrature rule to be non-negative?

(a) The highest degree is n − 1 for n even, n for n odd. (b) Placement of the n nodes adds an extra n degrees of freedom, thereby increasing the degree of the exactly integrable polynomial by n. (c) A simple quadrature rule uses a high-degree polynomial interpolant to approximate the function being integrated, thereby yielding an error term that depends upon a high-order derivative of the integrand. A composite quadrature rule divides the interval of integration into a number of panels, and applies a low-order rule on each. The error term then involves only a low-order derivative of the integrand. For functions whose derivatives increase rapidly with the order of differentiation, the composite rule is therefore more accurate. (d) The condition number κ for an n -point quadrature rule for the integral

∫ (^) b a f^ (x)^ dx^ is

κ =

∑^ n

i=

|wi|,

where the wi are the weights. It is also known that

∑^ n

i=

wi = b − a.

If the wi are all positive, then the above equations show that κ is simply equal to b − a. If some of the weights are negative, then

κ =

∑^ n

i=

|wi| >

∑^ n

i=

wi = b − a.

i.e., the algorithm is less well-conditioned.

  1. (Pencil-and-paper and possibly Matlab) Suppose that you are using Simpson’s rule to approximate an integral over the interval [a, b]. If you wish to obtain a more accurate approximation of the integral, which of the following will gain more accuracy?

(a) Dividing the interval in half and using Simpson’s rule on each subinterval. (b) Using a closed Newton-Cotes rule with the same 5 points as nodes.

Support your answer with an error analysis. Test your conclusion experimentally with a few sample integrals. First, recall that Simpson’s rule is a 3-point rule, and when applied over the interval [a, b], yields the approximation

I(f ) =

∫ (^) b

a

f (x) dx =

h 3

[

f (a) + 4f

a + b 2

  • f (b)

]

(b − a)^3 12 f ′′′(c), c ∈ [a, b].

Upon dividing the interval [a, b] into two halves and applying Simpson’s rule on each half, note that we are making use of 5 node points: a, a + h, a + 2h, a + 3h, and a + 4h ≡ b, h = (b − a)/ 4. The resulting composite Simpson’s rule is

I(f ) =

∫ (^) b

a

f (x) dx =

h 3

[f (a) + 4f (a + h) + 2f (a + 2h) + 4f (a + 3h) + f (b)] −

h^3 12

[f ′′′(c 1 ) + f ′′′(c 2 ),

where c 1 ∈ [a, a + 2h] and c 2 ∈ [a + 2h, b]. We can consolidate the error term and rewrite the above expression as

I(f ) =

∫ (^) b

a

f (x) dx = h 3

[f (a) + 4f (a + h) + 2f (a + 2h) + 4f (a + 3h) + f (b)] − h^3 6

f ′′′(c), c ∈ [a, b].

The closed 5-point Newton-Cotes rule, for which the error term is derived in problem 4(b) below, gives ∫ (^) a+4h

a

f (x) dx =

2 h 45

[7f (a) + 32f (a + h) + 12f (a + 2h) + 32f (a + 3h) + 7f (a + 4h) −

8 h^7 945

f (6)(c).

It is clear that for small values of h, the 5-point Newton-Cotes rule is more accurate unless f (x) is such that its 6th derivative is much larger than its 3rd derivative. In the latter case the composite Simpson’s rule may be more accurate. See the attached Matlab Log where the integrals

I 1 =

0

sin(0. 5 x) dx, I 2 =

0

sin(50x) dx.

are computed by each of the two methods. In the second integral the derivatives increase rapidly, and it is found that I 1 is computed more accurately by the Newton-Cotes rule and I 2 by the composite Simpson’s rule.

  1. (Pencil-and-paper) Consider the following 3-point quadrature rule for the integral I =

− 1 f^ (x)^ dx^ : Q(f ) = w[f (x 1 ) + f (x 2 ) + f (x 3 )].

This rule has unknown nodes and the same weight for all the terms. Find the weight and the nodes by using the conditions that the method is exact for f (x) = 1, x, x^2 ,... etc. What is the degree of precision of the resulting rule? Since there are 4 unknowns to be found, we require that the method be exact for the 4 monomials 1 , x, x^2 , and x^3 , and are led to the following equations.

3 w =

− 1

dx = 2, (1)

w(x 1 + x 2 + x 3 ) =

− 1

xdx = 0, (2)

w(x^21 + x^22 + x^23 ) =

− 1

x^2 dx =

w(x^31 + x^32 + x^33 ) =

− 1

x^3 dx = 0. (4)

  1. (Pencil-and-paper and Matlab used as a calculator) Text: 5.5 Exercises, page 279, problem 2(d), 4(d).

(a) The integral is

I =

− 1

cos πx dx.

The Gaussian rule for n = 3 is (see Table on page 277 of the Text)

G 3 (f ) = w 1 f (x 1 ) + w 2 f (x 2 ) + w 3 f (x 3 )

where x 1 = −x 3 = − 1 /

3 , x 2 = 0, w 1 = w 3 = 5/ 9 , w 2 = 8/ 9. Application of the rule yields G 3 (f ) = 0.044908 which is also the error since the exact answer is 0. (b) The integral is

I =

1

x^2 ln x dx.

The transformation x = 2 + t leads to

I =

− 1

(2 + t)^2 ln(2 + t) dt.

  1. (Pencil-and-paper and Matlab) Text: 5.4 Computer Problems, page 273, problem 6(f).

See attached Matlab log. The Matlab script is a modified version of the adaptive quadrature script provided on page 271 of the Text.

  1. (Extra Credit, Pencil-and-paper and Matlab) Repeat problem 6 above with Adaptive Simpson’s Quadra- ture. See attached Matlab log. The Matlab script is a modified version of that used in problem 6 above.

HW6, Problem 2.

Matlab Log

% ScriptFile HW6P2.m

clc

% Specify functions

f1=@(x) sin(0.5*x);

f2=@(x) sin(50*x);

% Specify interval width

h=0.05;

% Composite Simpson's

Q1S=(h/3)(f1(0)+4f1(h)+2f1(2h)+4f1(3h)+f1(4*h));

Q2S=(h/3)(f2(0)+4f2(h)+2f2(2h)+4f2(3h)+f2(4*h));

% 5-point Newton-Cotes

Q15=(2h/45)(7f1(0)+32f1(h)+12f1(2h)+32f1(3h)+7f1(4h));

Q25=(2h/45)(7f2(0)+32f2(h)+12f2(2h)+32f2(3h)+7f2(4h));

% "Exact" Solutions

I1=quadl(f1,0,4*h,1e-06);

I2=quadl(f2,0,4*h,1e-06);

% Errors

E1S=I1-Q1S; E15=I1-Q15;

E2S=I2-Q2S; E25=I2-Q25;

% Display results

disp('Function 1: sin(0.5*x)');

fprintf('Exact I1= %10.6e, Simp= %10.6e, NC5= %10.6e ...

\n',I1,Q1S,Q15);

fprintf('Error Simp= %10.6e, Error NC5= %10.6e \n',E1S,E15);

disp('Function 2: sin(50*x)');

fprintf('Exact I2= %10.6e, Simp= %10.6e, NC5= %10.6e ...

\n',I2,Q2S,Q25);

fprintf('Error Simp= %10.6e, Error NC5= %10.6e \n',E2S,E25);

Numerical Output

Function 1: sin(0.5*x)

Exact I1= 9.991669e-03, Simp= 9.991669e-03, NC5= 9.991669e-

Error Simp= -2.168492e-11, Error NC5= 5.164272e-

Function 2: sin(50*x)

Exact I2= 3.678143e-02, Simp= 6.140031e-02, NC5= 7.522638e-

Error Simp= -2.461888e-02, Error NC5= -3.844494e-

HW6, Problem 7.

Matlab Log

% Script File HW6P7.m

% Adaptive Quadrature using Simpson's rule

% Specify function and limits of integration

clc

clear all

f=@(x) cos(exp(x));

a0=0; b0=pi;

% Specify tolerance

tol0=0.5e-8;

% Begin adaptive procedure

sum=0; n=1; a(1)=a0; b(1)=b0; tol(1)=tol0;

app(1)=simp(f,a,b);

while n>

c=(a(n)+b(n))/2;

oldapp=app(n);

app(n)=simp(f,a(n),c);

app(n+1)=simp(f,c,b(n));

if abs(oldapp-(app(n)+app(n+1)))<15*tol(n)

sum=sum+app(n)+app(n+1); % success

n=n-1; % done with interval

else

b(n+1)=b(n);b(n)=c; % set up new intervals

a(n+1)=c;

tol(n)=tol(n)/2; tol(n+1)=tol(n);

n=n+1; % go to end of list,

repeat

end

end

% "Exact" solution using quadl

exact=quadl(f,a0,b0,tol0);

% Print result

fprintf('Numerical = %12.8e, Exact = %12.8e \n', sum, exact);

function s=simp(f,a,b)

s=(f(a)+4f((a+b)/2)+f(b))(b-a)/6;

Numerical Output

Numerical = -3.75940474e-01,

Exact = -3.75940475e-