<<

AMath 567, Autumn 2011 Sample Solutions for Assignment 2. Reading: Finish Ch 1. Read Secs 2.1-2.3 and Sec. 3.1.

1. Do ONE of the following two problems: (a) Use MATLAB or another programming language to fit a of degree 12 to the Runge 1 f(x)= , 1+ x2 interpolating the function at 13 equally spaced points between −5 and 5. (In MATLAB, you can set the points with the command x = [-5:5/6:5]; and you can then use routine polyfit to find the coefficients of a 12th degree polynomial that interpolates f at those points: p = polyfit(x,1./(1+x.^2). You can then use polyval to evaluate the polynomial at points between −5 and 5. Evaluate it at more than just the 13 points; say, xx = [-5:.01:5]; yy = polyval(p,xx).) Turn in a plot of f and the polynomial interpolant on the same graph.

Interpolating the Runge Function 2

1

0

−1

−2 ) and degree 12 interpolation polynomial 2 1/(1+x −3

−4 −5 −4 −3 −2 −1 0 1 2 3 4 5 x

(b) Write down the second degree (n = 2) Bernstein polynomial, n n k n−k Bn(x; f)= f(k/n) x (1 − x) , k k=0 for the function f in part (a). You will first have to the interval [−5, 5] to [0, 1] so that you get a function whose values on this interval match those of f on [−5, 5]. Then evaluate B2 for this function. Sketch the graph of the function on [0, 1] and sketch the Bernstein polynomial on this same interval. To map [−5, 5] to [0, 1], set y =(x + 5)/10. Then x = 10y + 5. Thus we should look at the function 1 g(y)= , y ∈ [0, 1]. 1+(10y − 5)2 The second degree Bernstein polynomial is 2 2 k 2−k B2(y; g) = g(k/2) y (1 − y) k k=0 25 25 1 = − y2 + y + . 13 13 26

1 1

0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

2. Let f be an even function in C[−1, 1]; i.e., f(x)= f(−x) ∀x ∈ [−1, 1]. The Weierstrass approximation theorem tells us that f can be approximated to arbitrary accuracy in the ∞-norm by a polynomial. Show that f can be approximated to arbitrary accuracy n 2j in the ∞-norm by an even polynomial (a polynomial of the form j=0 cjx ). By the Weierstrass Approximation Theorem, f can be approximated to any n j desired accuracy ǫ by a polynomial p(x)= j=0 cjx ; that is, we can choose the degree n and the coefficients c0,...,cnso that f − p∞ ≤ ǫ. Write p(x) as pe(x)+ po(x), where pe consists of the even terms and po of the odd [n/2] 2k [(n−1)/2] 2k+1 terms; that is, pe(x) = k=0 c2kx and po(x) = k=0 c2k+1x . Since f(−x)= f(x), pe(−x)=pe(x), and po(−x)= −po(x), we can write for each x ∈ [−1, 1], |f(x) − (pe(x)+ po(x))| ≤ ǫ, and

|f(−x) − (pe(−x) − po(−x))| = |f(x) − (pe(x) − po(x))| ≤ ǫ. Adding these inequalities, we have 1 |f(x) − p (x)| = |(f(x) − (p (x)+ p (x))+(f(x) − (p (x) − p (x))| ≤ e 2 e o e o 1 [|f(x) − (p (x)+ p (x))| + |f(x) − (p (x) − p (x)|]= ǫ. 2 e o e o

Thus the even polynomial pe approximates f to the desired accuracy ǫ; that is, f − pe∞ ≤ ǫ.

3. Sometimes, instead of approximating a by a single polynomial of high degree, one approximates it by piecewise of low degree. For example, if f is continuous on the interval [0, 1], one might divide the interval [0, 1] into n 1 subintervals, each of width h = n , and approximate f by a function that matches f at the endpoints of each subinterval and is linear within each subinterval, as pictured below: 0.25

0.2

0.15 y

0.1

0.05

0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 x

2 (a) Suppose the interval [0, 1] has been divided into n equal subintervals, with end- points x0 = 0, x1 = 1/n,...,xn−1 = (n − 1)/n, xn = 1, as described above. Consider the “hat” functions:

x−xj−1 h , xj−1 ≤ x ≤ xj xj+1−x ϕj(x)=  h , xj ≤ x ≤ xj+1 , j =1,...,n − 1.  0 otherwise



1

phi 0.8 3

y 0.6

0.4

0.2

0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 x Show that any continuous piecewise linear function ϕ on this grid with ϕ(0) = ϕ(1) = 0 can be written as a linear combination of the ϕj’s; that is, determine n−1 values c1,...,cn−1 such that ϕ(x)= j=1 cjϕj(x). n−1 ϕ(x)= ϕ(xj)ϕj(x). j=1 This must be the linear combination since it matches ϕ at the nodes, and the linear piece in each subinterval is completely determined by its values at the endpoints of the subinterval. (b) Show that the set of continuous piecewise linear functions is dense in (C([0, 1], ∞); i.e., every function f in C([0, 1]) can be approximated arbitrarily well in the ∞-norm by a continuous piecewise linear function. [Hint: Since f is continuous on the compact set [0, 1], it is uniformly continuous. That is, for any ǫ > 0 there exists δ > 0 such that whenever x, y ∈ [0, 1] and |x − y| < δ, we have |f(x) − f(y)| < ǫ. Try approximating f by its piecewise linear interpolant on a grid with spacing h < δ.] As noted in the hint, since f is uniformly continuous, given ǫ > 0 there exists δ > 0 such that |x − y| < δ =⇒ |f(x) − f(y)| < ǫ. Let ℓh be the piecewise linear interpolant of f on a grid with spacing h < δ. The values of f(x) in a subinterval [xj, xj+1] lie within ǫ of both f(xj) and f(xj+1) since the interval width is less than δ, while the values of ℓh(x) lie between f(xj) and f(xj+1). Therefore |f(x) − ℓh(x)| ≤ max{|f(x) − f(xj)|, |f(x) − f(xj+1)|} < ǫ.

4. Let A be an n by n . Given a vector norm (a norm on Rn or Cn, like the Euclidean norm or the 1-norm or the ∞-norm), one defines the corresponding operator v norm of A to be A = supv=1 A . Verify that this defines a norm on the set of n by n matrices, and explain why sup could be replaced by max in the definition.

3 Since is a continuous function and {v ∈ Fn : v =1} is a compact set in Fn = Rn or Cn, the sup is actually attained and hence can be replaced by max in the definition. To verify that the operator norm is a norm, we note that: (a) A ≥ 0 since Av ≥ 0 for all v. A = 0 if and only if Av = 0 for all v with v = 1 if and only if A is the zero matrix; if A had a nonzero entry, say, in column j, then the product of A with the jth unit vector (the vector with a 1 in position j and zeros elsewhere, multiplied by a if necessary to make it have norm one for the given norm) would be a nonzero vector and hence would have a positive norm. v v v (b) For α a scalar, αA = supv=1 αA = supv=1 |α|A = |α| supv=1 A = |α| A. v v v v (c) A+B = supv=1 (A+B) ≤ supv=1(A +B ) ≤ supv=1 A + w supw=1 B = A + B. (d) One also can show that AB≤AB, which is sometimes listed as a requirement for a matrix norm. To see this, note that AB = v v v w v v supv=1 AB . For each with = 1, let v = B /B , so that wv ranges over all or some subset of the vectors with norm 1. Then v w v w AB = supv=1(B A v ≤ supv=1 B supw=1 A = BA.

To solve a large linear system Ax = b (where the nonsingular n by n matrix A and the n-vector b are given), the following iterative procedure is sometimes used. First, write A as A = M − N, where M approximates A but is easier to invert than A. (For example, M might be the diagonal of A or the lower triangle of A.) Starting with an initial guess x(0) for the solution, form successive approximations satisfying Mx(k+1) = Nx(k) + b, k =0, 1,.... Thus, x(k+1) = g(x(k)), where g : Rn → Rn is defined by g(v) = M −1Nv + M −1b. Show that this iteration converges to the unique solution x = A−1b if M −1N < 1.

We will show that g is a contraction, mapping the complete Fn into itself. It will then follow from the contraction mapping theorem that g has a unique fixed point and that the Picard iteration defined above converges to this fixed point. To see that g is a contraction, note that for any two n-vectors v and w, g(v)−g(w) = M −1Nv−M −1Nw = M −1N(v−w)≤M −1Nv−w. Since M −1N < 1, it follows that g is a contraction. Therefore g has a unique fixed point x, and this must be the unique solution to the linear system, since g(x)= x ⇐⇒ M −1Nx+M −1b = x ⇐⇒ Nx+b = Mx ⇐⇒ (M−N)x = b ⇐⇒ Ax = b.

4