Homework 8 Solution - Numerical Analysis | MATH 128A, Assignments of Mathematical Methods for Numerical Analysis and Optimization

Material Type: Assignment; Class: Numerical Analysis; Subject: Mathematics; University: University of California - Berkeley; Term: Spring 2003;

Typology: Assignments

Pre 2010

Uploaded on 10/01/2009

koofers-user-jrm
koofers-user-jrm 🇺🇸

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Homework set #8 solutions, Math 128A
J. Xia
Sec 4.7: 1a, 3a, 7
1a. 3a.
Z1.5
1
x2ln xdx =1
4Z1
1µt+ 5
42
ln µt+ 5
4dt.
Let f(t) = ¡t+5
4¢2ln ¡t+5
4¢, then use Gaussian quadrature formula together with the
roots of the Legendre polynomials and the coefficients for Gaussian quadrature in
Table 4.11 of the textbook.
For n= 2,
Z1.5
1
x2ln xdx 1
4[f(0.5773502692) + f(0.5773502692)]
= 0.192268706.
For n= 4,
Z1.5
1
x2ln xdx 1
4[0.3478548451 ·f(0.8611363116) + 0.6521451548 ·f(0.3399810436)
+ 0.6521451548 ·f(0.3399810436) + 0.3478548451 ·f(0.8611363116)]
= 0.192259358.
The exact value is
Z1.5
1
x2ln xdx =1
3x3ln xx3
9|1.5
1(integration by parts)
= 0.1922593577.
We can see for n= 2, the |error|= 9.3483 ×106. But for n= 4, the |error|=
3×1010 and we get higher accuracy.
7. Assume otherwise the formula
Q(P) =
n
X
i=1
ciP(xi) (1)
has degree of precision greater than 2n1. Then it must also be exact for any
polynomial with degree 2n. Now we can easily find a counterexample. Let
P(x) = (xx1)2· · · (xxn)2,
where xi, i = 1,··· , n are the same as those in (1), i.e. the roots of the degree-n
Legendre polynomial.
Then the left hand side of (1)
Q(P) = Z1
1
P(x)dx =Z1
1
(xx1)2· · · (xxn)2dx > 0.
1
pf3
pf4

Partial preview of the text

Download Homework 8 Solution - Numerical Analysis | MATH 128A and more Assignments Mathematical Methods for Numerical Analysis and Optimization in PDF only on Docsity!

Homework set #8 solutions, Math 128A

J. Xia

Sec 4.7: 1a, 3a, 7

1a. 3a. (^) ∫

  1. 5 1

x^2 ln xdx =

− 1

t + 5 4

ln

t + 5 4

dt.

Let f (t) =

( (^) t+ 4

ln

( (^) t+ 4

, then use Gaussian quadrature formula together with the roots of the Legendre polynomials and the coefficients for Gaussian quadrature in Table 4.11 of the textbook. For n = 2, ∫ (^1). 5

1

x^2 ln xdx ≈

[f (0.5773502692) + f (− 0 .5773502692)]

= 0. 192268706.

For n = 4, ∫ (^1). 5

1

x^2 ln xdx ≈

[0. 3478548451 · f (0.8611363116) + 0. 6521451548 · f (0.3399810436)

    1. 6521451548 · f (− 0 .3399810436) + 0. 3478548451 · f (− 0 .8611363116)] = 0. 192259358.

The exact value is ∫ (^1). 5

1

x^2 ln xdx =

x^3 ln x −

x^3 9 |^11. 5 (integration by parts)

= 0. 1922593577.

We can see for n = 2, the |error| = 9. 3483 × 10 −^6. But for n = 4, the |error| = 3 × 10 −^10 and we get higher accuracy.

  1. Assume otherwise the formula

Q(P ) =

∑^ n

i=

ciP (xi) (1)

has degree of precision greater than 2n − 1. Then it must also be exact for any polynomial with degree 2n. Now we can easily find a counterexample. Let

P (x) = (x − x 1 )^2 · · · (x − xn)^2 ,

where xi, i = 1, · · · , n are the same as those in (1), i.e. the roots of the degree-n Legendre polynomial. Then the left hand side of (1)

Q(P ) =

− 1

P (x)dx =

− 1

(x − x 1 )^2 · · · (x − xn)^2 dx > 0.

(Here Q(P ) > 0 because of the following. All xi, i = 1, · · · , n are distinct points in (− 1 , 1), so there exists a point ¯x ∈ some (xi, xi+1) ⊂ (− 1 , 1) s.t. P (¯x) 6 = 0, and thus P (¯x) > 0. By the continuity of P (x) in (− 1 , 1), there exists a interval [¯x − ≤, ¯x + ≤] ⊂ (xi, xi+1) s.t. P (x) > 0 for all x ∈ [¯x − ≤, x¯ + ≤]. Again by continuity P (x) reaches its minimum in [¯x − ≤, x¯ + ≤] so P (x) > k > 0 for x ∈ [¯x − ≤, x¯ + ≤]. Thus

− 1 P^ (x)dx^ ≥^

∫ (^) x¯+≤ x ¯−≤ kdx^ = 2≤k >^ 0.) But the right hand side of (1)

∑^ n

i=

ciP (xi) =

∑^ n

i=

ci · 0 (because P (xi) = 0)

≡ 0. regardless of ci

Thus (1) cannot be true. Contradiction.

Sec 4.8: 1a, 5a, 7a(iv), 15a

1a. Algorithm 4.4(Simpson’s double integral) function J = dblsimp(a,b,c,d,f,m,n) J1 = 0; J2 = 0; J3 = 0; for i = 0:n x = a+ih; dx = d; cx = c; % Here c, d are constants. % When they are functions as in problem 3 % use dx=feval(d,x); cx=feval(c,x); HX = (dx-cx)/m; K1 = feval(f,x,cx)+feval(f,x,dx); K2 = 0; K3 = 0; for j = 1:m- y = cx+jHX; Q = feval(f,x,y); if mod(j,2) == 0 K2 = K2+Q; else K3 = K3+Q; end end L = (K1+2K2+4K3)HX/3; if i == 0 | i == n J1 = J1+L; elseif mod(i,2) == 0 J2 = J2+L; else J3 = J3+L; end end J = h(J1+2J2+4J3)/3; And define the function f. Run in matlab dblsimp(2.1,2.5,1.2,1.4,’f’,4,4)

We have

∫ (^1)

0

P 4 (x) x^1 /^4

dx =

0

x − x 3 6 x^1 /^4

dx =

0

(x^3 /^4 −

x^11 /^4 6 )dx =

Then (^) ∫ (^1)

0

x−^1 /^4 sin xdx =

0

P 4 (x) x^1 /^4

dx +

0

G(x)dx,

where

G(x) =

sin x−P 4 (x) x^1 /^4 ,^ when^0 < x <^1 0 , when x = 0.

Applying the Composite Simpson’s rule to integrate G(x) by hand or by the following code. function xi = cmpsimp(a,b,n,f) h = (b-a)/n; xi0 = feval(’f’,a)+feval(’f’,b); xi1 = 0; xi2 = 0; for i = 1:n- x = a+ih; if mod(i,2) == 0 xi2 = xi2+feval(’f’,x); else xi1 = xi1+feval(’f’,x); end end xi = h(xi0+2xi2+4xi1)/3; Function definition: function y = f(x) if x>0 & x <= 1 y = (sin(x).-x.+x.^3/6)./sqrt(sqrt(x)); elseif x == 0 y = 0; end We have (^) ∫ (^1)

0

P 4 (x) x^1 /^4

dx +

0

G(x)dx ≈ 0. 528416326.

3a. Let t = 1/x, then

∫ (^) ∞

1

x^2 + 9

dx =

1

1 /t^2 + 9

t^2

)dt =

0

1 + 9t^2

dt ≈ 0. 41126487.

The evaluation in the last step can be done with the previous code, Composite Simpson’s rule, in problem 1a.