CS514 Fll '00 Numericl Anlysis (Sketched) Solution of Homework 3 1. Questions from text in Chpter 3 Problem 1: 0 f 0 1 f 8 1 8(f 1 f 0 ) 1 f 4 2 8(f 2 f 1 ) 32(f 2 2f 1 f 0 ) 1 32 f 2 3 4(f 3 f 2 ) (f 64 3 3 3f 2 + 2f 1 ) (f 3 3 6f 2 + 8f 1 3f 0 ) Therefore, f 0 (0) = 1 3 (2f 3 24f 2 + 64f 1 42f 0 ) + e, nd jej» 1 1 1 8 4 2 M 4 4! = M 4 1536. Problem 6: () I(h) = 1 3 h3 + 2 7 h7=2 ; T (h) = 1 2 h3 + 1 2 h7=2 : (b) Then, E(h) = O(h 3 ) s h! 0: I(h) = 1 3 h3 + 2 3 h3=2 ; T (h) = 1 2 h3 + 1 2 h3=2 : Then, E(h) = O(h 3=2 ) s h! 0: Problem 7: The error is lrger by 1 1 2 order compred to (). f in () is in C 2 [0; h]; but f in (b) is in C[0; h]. 1
() By Tylor's Theorem, letting x k + 1 h be written s 2 x0, f(x) = f(x 0 ) + (x x 0 )f 0 (x 0 ) + 1 2 (x x0 ) 2 f 00 (ο(x)); x k» x» x k + h; where ο 2 [x k ; x k + h]. Integrting gives, Z +h f(x)dx = hf(x 0 ) + f 0 (x 0 ) Z +h (x x 0 )dx + 1 2 Z +h (x x 0 ) 2 f 00 (ο(x))dx: The second term on the right hnd side is zero nd pply Men Vlue Theorem, yields, Z +h f(x)dx = hf(x 0 ) + 1 2 f 00 (ο(x)) Clculte Hence, Z +h (b) Sum ll subintervls, Problem 8: () tht is, Z b 1 2 f 00 (ο(x)) Z +h Z +h (x x 0 ) 2 dx = h3 12 : (x x 0 ) 2 dx: f(x)dx = hf(x 0 )f(x 0 ) + h3 24 f 00 (ο k ); x k» ο k» x k + h: Z b X n 1 f(x)dx = h f(x 0 ) + h2 n 1 b f 00 (ο k ); 24 n X k=0 X k=0 n 1 f(x)dx = h f(x 0 ) + h2 24 (b )f 00 (ο);» ο» b: k=0 1 y 1 0 y 0 y 0 y 1 0 y 0 y 0 0 1 y 1 y 1 y 0 y 0 y 0 0 + y 1 y 1 y 0 y 0 0 1 (y 2 1 y 1 2y0) 0 p 3 (y; t) = y 1 + (t + 1)(y 0 y 1 ) + (t + 1)t(y 0 0 y 0 + y 1 ) + 1 2 (t + 1)t2 (y 1 y 1 2y 0 0): 2
Then, Z 1 p 3 (y; t)dt 1 = 2y 1 + 2(y 0 y 1 ) + 2 3 (y0 0 y 0 + y 1 ) + 1 3 (y 1 y 1 2y 0 0) = 1 3 (y 1 + 4y 0 + y 1 ): (b) E S (y) = Z 1 1 (t + 1)t 2 (t 1) y(4) (fi(t)) dt 4! = 1 90 y(4) (fi); 1» fi» 1: (c) Let n be even, h = (b )=n, x k = + kh, nd f k = f(x k ). Then, Z +2 f(x)dx = h Z 1 Let y(t) = f(x k+1 + th) in () nd (b), we obtin 1 f(x k+1 + th)dt: Z +2 Sum ll even k from 0 to n-2, f(x)dx = hf 1 3 (f k + 4f k+1 + f k+2 ) 1 90 h4 f (4) (ο k )g; Z b ο k = x k+1 + fih; 1» fi» 1: f(x)dx = n 2 X k is even. After clculting, we will get k=0 Z +2 f(x)dx; Z b f(x)dx = h 3 (f 0 + 4f 1 + 2f 2 + 4f 3 + + 2f n 2 + 4f n 1 + f n ) + E S n (f); where Problem 10: E S n (f) = b 180 h4 f (4) (ο);» ο» b: f = e x2 ; f 00 = 2(2x 2 1)e x2 ; f (4) = 4(4x 4 12x 2 + 3)e x2 : so, jf 00 j» 2; jf (4) j» 12 on [0; 1]: 3
() E T n = 1 12n 2 f 00 (ο); 0» ο» 1; we get, Tht is, je T n j» 1 6n 2» 1 2 10 6 if n 1 3 106 : n 103 p 3 ß 578: (b) we get, if Tht is, E S n = 1 180n 4 f (4) (ο); 0» ο» 1; je S n j» 1 180n 4 12 = 1 15n 4» 1 2 10 6 n 4 2 15 106 : n [ 200 15 ]1=4 10 ß 20: Problem 35 The re of unit disk cn be computed s A = 2 Z 1 1 (1 t 2 ) 1=2 dt = 2 Z 1 1 (1 t 2 )(1 t 2 ) 1=2 dt; hence cn be evluted exctly by 2 point Guss-Chebyshev qudrture rule pplied to f(t) = 1 t 2 : A = 2 ß 2 (1 t2 1 + 1 t 2 2) = ß(2 t 2 1 t2 2): But, nd Thus, t 1 = cos ß 4 = 1 p 2 t 2 = cos 3ß 4 = 1 p 2 : A = ß(2 1=2 1=2) = ß: 4
2. Mchine Assignment 1 in Chpter 3. After computing, we get The progrm is s following: e 1 (h) = ß (f 1 f 0 ) ; e 2 (h) = 2ß 2 f 1 2f 0 + f 1 ; h h 2 e 3 (h) = 6ß 3 f 2 3f 1 + 3f 0 f 1 h 3 ; e 4 (h) = 24ß 4 f 2 4f 1 + 6f 0 4f 1 + f 2 h 4 : % % Mchine ssignment 1 in Chpter 3, the problem description is not cler % fixed nd solve it. % index for -2-1 0 1 2 in f is 1 2 3 4 5 % formt long; i=[-2-1 0 1 2]; PI = 4*tn(1); E1 = PI; E2 = 2*pi^2; E3 = 6*pi^3; E4 = 24*pi^4; k = 0:10; h=2.^(-k-2); f = 1./ (1 - PI * (i'*h)); P = [ ((f(4,:)-f(3,:))./ h) ; ((f(4,:)-2*f(3,:)+f(2,:))./ (h.^2)); ((f(5,:)-3*f(4,:)+3*f(3,:)-f(2,:))./ (h.^3)); ((f(5,:)-4*f(4,:)+6*f(3,:)-4*f(2,:)+f(1,:))./ (h.^4)) ]; E = [E1 - ((f(4,:)-f(3,:))./ h) ; E2 - ((f(4,:)-2*f(3,:)+f(2,:))./ (h.^2)); E3 - ((f(5,:)-3*f(4,:)+3*f(3,:)-f(2,:))./ (h.^3)); E4 - ((f(5,:)-4*f(4,:)+6*f(3,:)-4*f(2,:)+f(1,:))./ (h.^4)) ]; R=[]; 5
for j=2:11 R = [R bs(e(:,j)./ E(:,j-1))]; end fid1 = fopen('ma3_1','w'); fprintf(fid1,' exct derivtes n'); fprintf(fid1,' %8.3f %8.3f %8.3f %8.3f n', E1, E2, E3, E4); fprintf(fid1,' pproximte derivtes n'); fprintf(fid1,' %8.3f %8.3f %8.3f %8.3f n', P); fprintf(fid1,' pproximte errors n'); fprintf(fid1,' %8.3f %8.3f %8.3f %8.3f n', E); fprintf(fid1,' r1 r2 r3 r4 n'); fprintf(fid1,' %8.3f %8.3f %8.3f %8.3f n', R); fclose(fid1); The result is s exct derivtes 3.142 19.739 186.038 2337.818 pproximte derivtes 14.639 51.518-850.651-4158.085 5.173 23.338 1024.958 7214.081 3.909 20.531 318.619 2874.910 3.484 19.931 233.744 2455.227 3.304 19.787 206.788 2366.272 3.221 19.751 195.759 2344.877 3.181 19.742 190.747 2339.580 3.161 19.740 188.356 2338.258 3.151 19.739 187.188 2337.930 3.146 19.739 186.611 2337.840 3.144 19.739 186.324 2337.781 pproximte errors -11.498-31.779 1036.688 6495.903-2.031-3.599-838.921-4876.262 6
-0.768-0.792-132.581-537.092-0.342-0.192-47.706-117.409-0.162-0.048-20.751-28.454-0.079-0.012-9.721-7.059-0.039-0.003-4.710-1.761-0.019-0.001-2.318-0.440-0.010-0.000-1.150-0.111-0.005-0.000-0.573-0.022-0.002-0.000-0.286 0.037 r1 r2 r3 r4 0.177 0.113 0.809 0.751 0.378 0.220 0.158 0.110 0.446 0.243 0.360 0.219 0.474 0.248 0.435 0.242 0.487 0.250 0.468 0.248 0.494 0.250 0.484 0.250 0.497 0.250 0.492 0.250 0.498 0.250 0.496 0.253 0.499 0.250 0.498 0.194 0.500 0.250 0.499 1.705 One cn relize tht the convergence order is O(h) for n = 1 nd n = 3, the rtion tends to 1. However, for n = 2 nd n = 4, the order is 2 O(h2 ) nd the rtio tends to be 1. 4 Rounding error occurs in the lst few vlues of n = 4 which corrupts the limit of the rtion. 3. Problem 3 on HW sheet. () trpezoid rule: Z 1 0 e x dx = 0:1( 1 2 e0 + 9X i=1 e i 10 + 1 2 e 1 ) ß 0:63265: Then the error is -0.00053. Z 1 0 e x dx = 0:63212 7
(b) gussin qudrture: Let ß 3 (t) = t 3 +p 1 t 2 +p t 2+p 3 : Since it is orthogonl to 1, t, nd t 2, one cn solve the coefficients which p 1 = 3, p 2 2 = 3, nd p 5 3 = 1. Then, we 20 cn get 3 roots for ß 3. Then, one need to find the weights w 1, w 2, nd w 3. Consider f(t) 1, f(t) t, nd f(t) t 2, then solve the liner eqution system nd get w 1, w 2, nd w 3. The results re s t 1 = 0:887298; t 2 = 0:5; t 3 = 0:112702; w 1 = 0:277778; w 2 = 0:444444; w 3 = 0:277778: And, Z 1 0 e x dx ß 0:632120 Z 1 0 e x dx = 0:6321205588 Then the error is -0.0000005588 (more precision pplied here). Therefore, gussin qudrture preforms better for this problem 4. Questions from text in Chpter 4. Problem 7: () Plot the function. Since there re three intersections with the line x = 0, there (b) No. Problem 21: () re 3 rel root. Their pproximted loction is -2, 2, nd 10.5 respectively. x n+1 ff = 1 2 (x n + x n ) ff = x2 n + 2ffx n 2x n = x2 n 2ffx n + ff 2 2x n = (x n + ff) 2 2x n : ) 1 2x n (b) Let f(x) = x 3. Then f 0 (x) = 3x 2. = x n+1 ff x n ff : x n+1 ff lim n!1 x n ff = n!1 lim 1 = 1 2x n 2ff : x n+1 = x n f(x n) f 0 (x n ) = x n x3 n = 3x3 x 3 + n n 3x 2 3x 2 n n 8
= 1 3 (2x n + x 2 n ): Then, Problem 22: () Therefore, x n+1 ff = 1 3 (2x n + x 2 n = 2x3 n + ff 3 3ffx 2 n 2x 2 n = (ff3 x 3 n) 3x 2 n(ff x n ) 3x 2 n ) ff = 2x3 n + 3ffx 2 n 3x 2 n = ff3 x 3 n + 3(x 3 n ffx 2 n) 3x 2 n ) x n+1 ff (x n ff) = ff + 2x n : 2 3x 2 n x n+1 ff lim n!1 (x n ff) = lim ff + 2x n 2 n!1 3x 2 n = (ff x n) 2 (ff + 2x n ) : 3x 2 n = 1 ff : d n = x n+1 x n = 1 2 ( x n x n ): (b) ) 2d n x n = x 2 n : ) x n 2 + 2dx n = 0: ) x n = 2d n ± p 4dn 2 + 4 2 = d n ± q d 2 n + : We ssume x 0 > 0, then x n > 0. Therefore, q x n = d n + d 2 + = + d2 p d 2 n n n d n + d 2 + : n ) x n = d n + p d 2 n + : ) x n = d n + p d 2 n + = 1 2 (x n 1 + = 1 2 ( d n 1 + qd 2n 1 + 1 + (d n 1 + x n 1 ) q d 2 n 1 + )): q p d n + d 2 + = 1 2 ((d n 1 d 2 + ) n 1 d 2 n n 1 d2 + d n 1 + n 1 = 1 2 ( qd 2 n 1 + d n 1 + d n 1 + q d 2 n 1 + ) qd 2n 1 + ) = q d 2 n 1 + : 9
() '(x) = 2 x, x 6= 0. Then, ' 0 (ff) = 2ff 1 6= 0: ) p q d n + d 2 + = d 2 + : n 1 n q ) d n + d 2 + = n qd 2n 1 + : ) q d 2 n + = ) d 2 n + = d 2 n ) q 2d n d 2 + = n 1 q d n : d 2 n 1 2d n 2 qd 2n 1 + + d 2 + : n 1 d2 n 1 d 2 n 1 + 2: Problem 35: Therefore, d 2 n 1 ) d n = 2 qd 2n 1 + : d 2 n 1 jd n j = 2 qd 2n 1 + : Clim j 2 x 2 j < 1, then x 2 ( 1; p 2) [ ( p 2; 1). It will converge only when x 0 = ± p 2. Otherwise, it never converges. (b) '(x) = x 2 + x 2. Then, ' 0 (ff) = 2ff + 1 6= 0: Clim j2x + 1j < 1, then x 2 ( 1; 0). It will never converge to the root. (c) '(x) = x+2, x 6= 1. Then, x+1 ' 0 (ff) = 1 6= 0: (ff + 1) 2 1 Clim j j < 1, then, x 2 ( 1; 2) [ (0; 1). (x+1) 2 converge when x 0 > 0. Since p 2 > 2, it will 5. Mchine Assignment 1 in Chpter 4. The progrm is s following: FORTRAN(f90) prt, min progrm 10
!! This is for Mchine Assignment 1 in Chpter 4! PROGRAM m4_1 rel e rel from, to, h integer i, n n=200 e = Eps()! For prt (): open(20, file='m4_1') from = 0.93 to = 1.07 h = (to-from)/n write(20,2) from write(20,2) to do i=0, n x = from+i*h write(20,1)(p(x)/e) enddo close(20) 1 formt(e16.7) 2 formt(f16.7)! For prt (b): open(20, file='m4_1b') from = 21.7 to = 22.2 h = (to-from)/n write(20,2) from write(20,2) to do i=0, n 11
x = from+i*h write(20,1)(pb(x)/e) enddo close(20) end rel function Eps() rel, b, c =4./3. b=-1 c=b+b+b Eps=bs(c-1) return end rel function p(x) rel x p=x**5-5*x**4+10*x**3-10*x**2+5*x-1; return end rel function pb(x) rel x pb=x**5-100*x**4+3995*x**3-79700*x**2+794004*x-3160088; return end MATLAB prt, for plot only % % for plot in Mchine ssignment 1 of Chpter 4, red file m4_1 nd m4_1b % fid1 = fopen('m4_1', 'r'); 12
p = fscnf(fid1, '%g', [203]); fclose(fid1); fid1 = fopen('m4_1b', 'r'); pb = fscnf(fid1, '%g', [203]); fclose(fid1); h = (p(2)-p(1))/200; hb = (pb(2)-pb(1))/200; i = p(1):h:p(2); ib = pb(1):hb:pb(2); figure; subplot(2,1,1); plot(i, p(3:203), '-'); title('polynomil /eps'); grid on; subplot(2,1,2); plot(ib, pb(3:203), '-'); title('polynomil b/eps') grid on; The plots re s below 13
20 polynomil /eps 10 0 10 20 0.92 0.94 0.96 0.98 1 1.02 1.04 1.06 1.08 1.1 5 x 107 polynomil b/eps 0 5 10 15 20 21.7 21.8 21.9 22 22.1 22.2 22.3 22.4 Figure 1: The plots for two functions 14