Massachusetts Institute of Technology 18.085: Computational Science and Engineering Gilbert Strang Spring 2016 Solution to Problem Set 1 Section 1.1 Exercise 4 1 −1 0 0 0 1 −1 0 , U4 = 0 0 1 −1 0 0 0 1 S4 = U4−1 1 0 = 0 0 1 1 0 0 1 1 1 0 1 1 . 1 1 We get 4 3 S4 S4T = 2 1 3 3 2 1 2 2 2 1 1 1 , 1 1 which is indeed equal to T4−1 . We can see it via MATLAB: >> S_4 = triu(ones(4)); >> S_4*S_4’; To show SS T is symmetric, we will use the fact that (AB)T = B T AT for any square matrix A, B. Hence, (SS T )T = (S T )T S T = SS T so SS T is symmetric. In fact it holds for any matrix S (doesn’t need to be symmetric or upper-triangular or even square-shaped). Exercise 5 K2−1 1 2 1 = . We may expect that det(K5 ) = 6. 3 1 2 5 4 3 4 8 6 1 3 6 9 K −1 = 6 2 4 6 1 2 3 We get det(K) = 6 and 2 4 6 8 4 1 2 3 4 5 MATLAB code: K = diag(2*ones(5,1))-diag(ones(4,1),1)-diag(ones(4,1),-1); det(K); det(K)*inv(K); Solution to Problem Set 1 Spring 2016 Exercise 20 2 3 4 5 1 2 2 2 4 6 12 8 16 1 2 = = = . 2 4 4 4 8 10 20 14 28 For n by n, this algorithm will operate n3 multiplications. Section 1.2 Exercise 2 Homogeneous solution would be uhom (x) = c1 x + c0 , and particular solution would be ( 0 if x < 0 upart (x) = −S(x) = −x if x ≥ 0. Hence the solution u(x) = uhom (x) + upart (x) is ( c1 x + c0 u(x) = (c1 − 1)x + c0 if x < 0 if x ≥ 0. Letting u(−2) = u(3) = 0, we get −2c1 + c0 = 0 3c1 + c0 = 3. So c0 = 6/5 and c1 = 3/5 and ( u(x) = Note that u is continuous at x = 0, i.e., 2 −1 −1 2 KU = 0 −1 0 0 3 (x + 2) 5 − 25 (x − 3) if x < 0 if x ≥ 0. two lines meet at x = 0. From finite difference, 3/5 0 0 0 −1 0 6/5 1 = = F. 2 −1 4/5 0 2/5 0 −1 2 2 Solution to Problem Set 1 Spring 2016 3 Exercise 6 ∆2 u(x) = u(x + ∆x) − 2u(x) + u(x − ∆x) = (x + ∆x)4 − 2x4 + (x − ∆x)4 = 12x2 (∆x)2 + 2(∆x)4 . Hence ∆2 u/(∆x)2 = 12x2 + 2(∆x)2 . On the other hand, u00 (x) = 12x2 . From ∆2 u(x) = (∆x)2 u00 (x) + c(∆x)4 u0000 (x), we have c = 1/12 (which is equal to 2/4!). Exercise 18 True solution will be the form of u(x) = c3 x3 + c2 x2 + c1 x + c0 , where 6c3 = 1, c2 = 0, c0 = 0, c3 + c2 + c1 + c0 = 0. First two equalities come from u00 (x) = x, and last two come from boundary condition. Hence u(x) = 61 x3 − 61 x. We would like to solve u00 = −f (x) using K with n = 4. Here f (x) = −x and h = 15 , and u(h) u(1/5) f (h) −h −1/5 u(2h) u(2/5) = F = f (2h) = −2h = −2/5 . U = u(3h) u(3/5) f (3h) −3h −3/5 u(4h) u(4/5) f (4h) −4h −4/5 1 KU = F , or explicitly h2 2 −1 0 0 u(1/5) −1/5 −1 2 −1 0 u(2/5) −2/5 25 0 −1 2 −1 u(3/5) = −3/5 . 0 0 −1 2 u(4/5) −4/5 We approximate d2 /dx2 by 1 K h2 n so Using MATLAB, we get 4 1 1 1 −1 3 · U= K F = 25 25 5 2 1 which exactly agrees with true solution. 3 6 4 2 2 4 6 3 −4/125 1 −1/5 2 −2/5 = −7/125 , 3 −3/5 −8/125 −6/125 4 −4/5 Solution to Problem Set 1 Spring 2016 Exercise 21 Pluging in u0 (0) = 0 and −u00 = f to Taylor expansion, we get 1 u(h) ≈ u(0) − h2 f (0). 2 Since u0 = u(0) and u1 = u(h), we get 1 u0 − u1 ≈ h2 f (0). 2 If we use this approximation instead of u0 − u1 ≈ u0 (0) = 0, then 1 −1 0 0 u(0) f (0)/2 1 −1 2 −1 0 u(h) = f (h) . 2 0 −1 2 −1 u(2h) f (2h) h 0 0 −1 2 u(3h) f (3h) By solving this equation, we get exact solution for Figure 1.4. 4