18.085 Problem Set 2 Robert Yi February 17, 2011 Section 1.1: 12, 26. Section 1.2: 14. Section 1.3: 8, 10. Section 1.4: 7, 8, 12. Section 1.5: 2, 13, 23, 29 Section 1.1 12. Carry out elimination on the 4 by 4 circulant matrix C4 to reach an upper triangular U (or try because C is singular. [L, U ] = lu(C) in MATLAB). Two points to notice: The last entry of U is The last column of U has new nonzeros. Explain why this “fill-in” happens. Entering in the code [L, U ] = lu(C) in MATLAB gives C = [ 2 -1 0 -1 ; -1 2 -1 0 ; 0 -1 2 -1; -1 0 -1 2 ] C = 2 -1 0 -1 -1 2 -1 0 0 -1 2 -1 -1 0 -1 2 >> [L, U]=lu(C) L = 1.0000 -0.5000 0 -0.5000 0 1.0000 -0.6667 -0.3333 0 0 1.0000 -1.0000 0 0 0 1.0000 -1.0000 1.5000 0 0 0 -1.0000 1.3333 0 -1.0000 -0.5000 -1.3333 0.0000 U = 2.0000 0 0 0 U is our upper triangular matrix, achieved via row reduction. The last entry of U is 0 (and hence the entire row) because C is singular. To preserve singularity, the fill-in must occur to make the row still add to one. 1 26. For which vectors v is toeplitz(v) a circulant matrx (cyclic diagonals)? Let’s write the form of a generic circulant For an n by n matrix, we have n1 nn nn−1 .. . n2 n by n matrix. We get n2 n1 n3 nn .. n3 ... . ... nn nn−1 nn−2 .. . n1 But for a toeplitz matrix, we need this to be symmetric. So our restriction is n2 = nn , n3 = nn−1 , n4 = nn−2 , etc. Or in other words, aside from the first entry of vector v, which has no restriction, the rest of the vector must be symmetric about its middle term (or lack thereof). E.g. in the vector [2 − 10 − 1], the vector, aside from the first entry 2, is symmetric about 0, the center of the remaining vector. Section 1.2 14 Part (a). Solve −u00 = 12x2 with free-fixed conditions u0 (0) = 0 and u(1) = 0. The complete solution involves integrating f (x) = 12x2 twice, plus Cx + D. Solving this without finite differences, but directly gives us −u00 = 12x2 u0 = −4x3 + C, and u0 (0) = 0 = C u = −x4 + D, and u(1) = 0 = −1 + D ⇒ D = 1 u = −x4 + 1 Part (b). With h = 1 n+1 and n = 3, 7, 15, compute the discrete u1 , ..., un using Tn : ui+1 − 2ui + ui−1 = 12(ih)2 with u0 = 0 and un+1 = 0 h2 Compare ui with the exact answer at the center point x = ih = 1/2. Is the error proportional to h or h2 ? The MATLAB code for constructing matrix T and vector v, and solving for u is n=3; h=1/(n+1); Tn = toeplitz([2 -1 zeros(1,n-2)]); Tn(1,1) = 1; v=[1:n]; for i=1:n; v(i) = 12*(v(i)*h)^2; end u=(Tn/(h^2))\v’ 2 For n = 3, the output from MATLAB is: u = 0.9375 0.8906 0.6563 1/2 For x = ih = 1/2, or i = 1/4 = 2, u2 = 0.8906. The actual value at this point is 1−(1/2)4 = 0.9375, so the difference is 0.9375 − 0.8906 = 0.0469, while h = 0.25. For n = 7, the output from MATLAB is: u = 0.9844 0.9814 0.9668 0.9258 0.8379 0.6768 0.4102 For x = ih = 1/2, or i = 1/2 1/8 = 4, u4 = 0.9258. The difference between this and the actual value is 0.0117, while h = 0.125. And for n = 15, the output from MATLAB is: u = 0.9961 0.9959 0.9950 0.9924 0.9869 0.9769 0.9602 0.9346 0.8972 0.8450 0.7745 0.6819 0.5629 0.4129 0.2271 1/2 For x = ih = 1/2, or i = 1/16 = 8, u8 = 0.9346. The difference between this and the actual value is 0.0029, while h = 0.0625. It seems that the error is proportional to h2 . Dividing the error by h2 for each of these different values of n gives us a factor of approximately 0.75. This makes sense, because this is what we calculated to be the error via Taylor series. Section 1.3 8 Factor these symmetric matrices into A = LDLT with pivots in D: 3 2 1 0 1 3 1 b and and 1 2 1 3 2 b c 0 1 2 1 3 For , row reduction gives us l21 = 3. So 3 2 1 0 1 3 LU = 3 1 0 −7 1 0 1 0 1 3 T LDL = 3 1 0 −7 0 1 1 b For , row reduction gives us l21 = b. So b c 1 b 1 0 LU = 0 c − b2 b 1 1 b 1 0 1 0 LDLT = 0 1 0 c − b2 b 1 2 1 0 2 1 0 2 1 0 For 1 2 1, row reduction gives first l21 = 1/2 ⇒ 0 3/2 1, and l32 = 2/3 ⇒ 0 3/2 1 . 0 0 4/3 0 1 2 0 1 2 1 0 0 2 1 0 LU = 1/2 1 0 0 3/2 1 0 2/3 1 0 0 4/3 1 0 0 2 0 0 1 1/2 0 LDLT = 1/2 1 0 0 3/2 0 0 1 2/3 0 2/3 1 0 0 4/3 0 0 1 10 The all-ones matrix ones(4) is positive semidefinite. Find all its pivots (zero not allowed). Find its determinant and try eig(ones(4)). Factor it into a 4 by 1 matrix L times a 1 by 4 matrix LT . The matrix in question is 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 There is clearly only one nonzero pivot, and that’s 1. Row reducing gives us 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 4 To get this, we used the operations l21 = 1, l31 = 1, l41 = 1. Thus, we can factor this into a 4 by 1 matrix times a 1 by 4 matrix: 1 1 1 1 1 1 1 1 The determinant of ones(4) is 0, which is the product of the pivots. eig(ones(4)) gives us >> eig(ones(4)) ans = -0.0000 0 0.0000 4.0000 Section 1.4 7. A difference of point loads, f (x) = δ(x − 31 ) − δ(x − 32 ), does allow a free-free solution to −u00 = f . Find infinitely many solutions with u0 (0) = 0 and u0 (1) = 0. We have d2 u 1 2 − 2 =δ x− −δ x− dx 3 3 which translates to a positive (downward) load at x = 1/3, and a negative (upward) load at x = 2/3. In other words, at x = 1/3, the slope must drop by 1, and at x = 2/3, the slope increases by 1. We are dealing with a ramp function that changes slope twice — so we have 3 equations describing the motion at each of the different sections. Before x = 1/3, our solution is of the form u = Ax + B. Between x = 1/3 and x = 2/3, our solution is of the same form, which we will call u = Cx + D. And, finally, after x = 2/3, call our solution Ex + F . We have 2 free-free boundary conditions, but we also have the requirement that the function be continuous at each of the junctions, and that the slope of the function change by 1 (down by 1, and up by 1, respectively for each of the junctions). This gives us 6 boundary conditions: u0 (0) = 0 ⇒ A = 0 u0 (1) = 0 ⇒ E = 0 1 1 1 No jump at u = : A +B =C +D 3 3 3 2 2 2 No jump at u = : C + D = E + F 3 3 3 1 : A−C =1 3 2 Slope increases by 1 at u = : E − C = 1 3 Slope drops by 1 at u = 5 This gives us only one equation left to solve 1 B =− +D 3 2 D=F+ 3 2 1 B =− +F + 3 3 1 = +F 3 So our unknowns are A=0 1 B = +F 3 C = −1 2 D = +F 3 E=0 Our solution is given by 1 1 + f for 0 < x < 3 3 2 1 2 u = −x + ( + f ) for < x < 3 3 3 2 u = f for x > 3 for some parameter f . So we have found infinitely many solutions. Using the matrix method with B for free-free conditions should yield the same result, with one linearly dependent column yielding infinitely many solutions. u= 8. The difference f (x) = δ(x − 13 ) − δ x − 32 has zero total load, and −u00 = f (x) can also be solved with periodic boundary conditions. Find a particular solution upart (x) and then complete solution upart + unull . The complete solution is given by R(x) + Cx + D, where R(x), the ramp, is the particular solution, and Cx + D satisfies the homogeneous equation u00 = 0. In the previous problem, the piece-wise function incorporates both of these solutions — the ramp gives continuity and slope changes, while the homogeneous solution explains what happens within these regions. Once again, before x = 31 , our solution is of the form u = Ax + B. Between x = 13 and x = 23 , our solution is of the same form, which we will call u = Cx + D. And, finally, after x = 32 , call our solution Ex + F . The periodic boundary condition we will write as u0 (0) = u0 (1), and u(0) = u(1). u0 (0) = u0 (1) ⇒ A = E u(0) = u(1) ⇒ B = A + F or F = B − A 1 1 1 No jump at u = : A +B =C +D 3 3 3 6 No jump at u = 2 : C 3 2 2 2 +D =E +F =A +B−A 3 3 3 1 : A − C = 1 or C = A − 1 3 2 Slope increases by 1 at u = : A − C = 1 3 Slope drops by 1 at u = We can rewrite our jump condition at u = 13 as 1 1 + B = (A − 1) +D A 3 3 1 1 1 +B =A − +D ⇒A 3 3 3 ⇒B =D− And at u = 32 : 1 3 1 2 +D =B−A (A − 1) 3 3 2 2 1 1 = − − A ⇒A − + D D 3 3 3 3 1 3 ⇒A= So our unknowns are given by A= 1 3 B =D− C=− 1 3 2 3 D E= 1 3 F =B−A=D− 2 3 Our equations are 1 1 1 u = x + D − , for 0 < x < 3 3 3 2 1 2 u = − x + D, for < x < 3 3 3 1 2 2 u = x + D − , for x > 3 3 3 The null solution is 7 12. The cubic spline C(x) solves the fourth-order equation u0000 = δ(x). What is the complete solution u(x) with four arbitrary constants? Choose those constants so that u(1) = u00 (1) = u(−1) = u00 (−1) = 0. This gives the bending of a uniform simply supported beam under a point load. The complete solution u(x) with four arbitrary constants is u(x) = C(x) + Ax3 + Bx2 + Dx + E The derivatives of this are u0 (x) = Q(x) + 3Ax2 + 2Bx + D, where Q is a quadratic spline u00 (x) = R(x) + 6Ax + 2B Plugging in our boundary conditions, we have u(1) = 1 +A+B+D+E =0 6 u00 (1) = 1 + 6A + 2B = 0 u(−1) = −A + B − D + E = 0 u00 (−1) = −6A + 2B = 0 Solving these gives us A = −1/12 B = −1/4 D=0 E = 1/6 So our equation is given by u(x) = C(x) − 1 3 1 2 1 x − x + 12 4 6 Section 1.5 2. When you multiply the eigenvector y = (sin πh, sin 2πh, ...) by K, the first row will produce a multiple of sin πh. Find that multiplier λ by a double-angle formula for sin 2πh. (Ky)1 = 2 sin πh − 1 sin 2πh = λ sin πh Then λ = . The above formula is the first row of K, with entries (2, −1, 0...) yields the above equation when multiplied by y. This equation becomes (Ky)1 = 2 sin πh − 2 sin πh cos πh = sin πh(2 − 2 cos πh) So λ = 2 − 2 cos πh, as expected. 8 13. Suppose A = SΛS −1 . What is the eigenvalue matrix for A + 2I? What is the eigenvector matrix? Check that A + 2I = ( )( )( )−1 . A + 2I = SΛS −1 + 2I = SΛS −1 + 2SIS −1 = S(Λ + 2I)S −1 The eigenvalue matrix for A + 2I is just Λ + 2I (i.e., (eigenvalues of A + 2I) = (eigenvalues of A) + 2). The eigenvector matrix for A + 2I, as we can see from the above relation, is just the same as the eigenvector matrix for A. Multiplying out S(Λ + 2I)S −1 gives us A + 2I, as expected. 23 Find λ’s and x’s so that u = eλt x solves du 4 3 = u 0 1 dt What combination u = c1 eλ1 t x1 + c2 eλ2 t x2 starts from u(0) = (5, −2)? Because this matrix is upper triangular, the eigenvalues λ are just the pivots — i.e. 4 and 1. The associated eigenvectors, x, are (1, 0) for 4, and (−1, 1) for 1. For u(0) = (5, −2) to be satisfied, we need c1 x1 + c2 x2 = c1 (1, 0) + c2 (−1, 1) = (5, −2). This requires c2 = −2, because c1 cannot change the second entry, and so c1 = 3. 29 Here is a quick “proof ” that the eigenvalues of all real matrices are real: Ax = λx gives xT Ax = λxT x so λ = xT Ax is real. xT x Find the flaw in this reasoning — a hidden assumption that is not justified. This assumes that the eigenvectors are also real, or else the inner product xT x could be imaginary (you’d have to multiply by the complex conjugate for the i’s to always go away). For example, if one of the entries of the eigenvector were 1 − i, xT x would yield an entry −2i, which is imaginary. 9