ENGRD 241: Engineering Computation December 20, 2001 SOLUTION TO FINAL EXAM This is an open-book, open-notes, and open-problem-set examination. Each problem starts on a separate page. Do all work on these sheets, and confine your solution to each problem to its own page, using the back of the page if necessary. Because these sheets may be temporarily separated for grading purposes, be sure to print your name on each and every page, and to observe and sign the pledge on this cover sheet. Show all work (including equations, formulas, and sketches where appropriate), and include only an appropriate number of significant figures for numerical values. Read all problems before beginning and follow directions carefully. Problems have the value indicated, and the total number of points is 150 for the 2½-hour (150-minute) examination – plan your time accordingly. Partial credit is available for all problems, so you are advised to work on all of them. You must submit all of these pages upon completion of the exam, whether or not you have attempted all problems. Name (Print): _______________________________________ Academic integrity is expected of all students of Cornell University at all times, whether in the presence or absence of members of the faculty. Understanding this, I declare that I shall not give, use, or receive unauthorized aid in this examination. Signature: _____________________________ Grading Summary: Problem Score Value 1 15 2 15 3 20 4 15 5 15 6 20 7 20 8 15 9 15 Total 150 Letter Grade ENGRD 241 Final Exam Name (Print): ________________________ Fall 2001 1. Ordinary Differential Equations, Initial Value Problems [15 points] Consider the first-order equation with initial condition dy y' y ex 1 y (0) 0.5 dx (a) Use a value of Δx = h = 1.0 to find y(1) by the “classical” fourth-order Runge-Kutta (RK) method, showing all equations and work. (b) By how much would the truncation error in y(1) decrease if one used a step size of Δx = h = 0.25? [Do not solve again for Δx = h = 0.25.] (c) Briefly explain the significance (i.e., the mathematical or graphical nature) of the k’s in RK methods, using the 4th-order RK method as an example. (a) f ( x, y ) y e x 1 x0 0 y0 0.5 1 yi 1 yi k1 2k2 2k3 k4 h 6 k1 f xi , yi 0.5 e0 1 1.5 h 1 y1 y (1) ? 1 1 k2 f xi h, yi hk1 f (0.5,1.25) 1.25 e 0.5 1 3.0609 2 2 1 1 k3 f xi h, yi hk2 f (0.5, 2.0305) 2.0305 e 0.5 1 4.3477 2 2 k4 f xi h, yi hk3 f (1.0, 4.8477) 4.8477 e1 1 14.1774 (b) (c) (25.40) (25.40a) (25.40b) (25.40c) (25.40d) 1 y1 y (1) 0.5 1.5 2(3.0609) 2(4.3477) 14.1774 1 5.5824 6 th 4 The 4 -order RK method is O(h ) – from the name and C&C p. 702. Therefore, as h goes from 1.0 to 0.25, the truncation error decreases by a multiplicative factor of (0.25/1.0) 4 = 0.0039 The k’s in the RK methods are approximations of the slope y' at different locations along the step. For the 4th-order method, k1 is the slope at the beginning of the step, k2 is a first estimate of the slope at the middle of the step, k3 is an improved estimate at the middle, and k4 is an estimate of the slope at the end of the step. These slopes are then combined in a weighted average to produce an effective slope for the solution step, Eq. (25.40). 2. Ordinary Differential Equations, Boundary Value Problems [15 Points] You wish to solve the following boundary value problem for the steady-state temperature in a rod of length 10m (C&C Problems 27.1-27.3): d 2T 0.1T 0 T (0) 200 T (10) 100 dx 2 (a) For a finite difference solution, write the discrete version of this equation at a typical interior point x = xi using O(h2) finite divided difference operators. Assume that Δx = h = 0.5 is uniform throughout the length of the rod. [Do not write out the full matrix equations for this problem, just write the one equation for the one typical interior point, i.e., the computational “molecule.”] ENGRD 241 Final Exam (b) (a) (b) Name (Print): ________________________ Fall 2001 You now decide that it would be more convenient to solve this problem by the shooting method (garden hose method) because you have handy a flexible and well-designed Excel spreadsheet for the fourth-order Runge-Kutta method. (i) Re-write the second-order equation as two first-order differential equations that you will use in your spreadsheet macros. (ii) Using Δx = h = 0.2, you obtain the following values from your spreadsheet corresponding to two assumed (trial) initial conditions for T'(0): When T'(0) = –60, you find T(10) = 129.481º When T'(0) = –65, you find T(10) = –56.951º What value of T'(0) would you use next? Is this likely to give you a solution that satisfies the “far” boundary condition? Why? Ti 1 2Ti Ti 1 0.1Ti 0 or Ti 1 2.025 Ti Ti 1 0 h2 dT (i) Let z , then the two first-order equations are: dx dT dz T' f ( x, T , z ) z and z' g ( x, T , z ) 0.1T dx dx (2) (1) z –z (1) (iii) From Lecture Notes 7C, page 1, with T'(0) = z0: zo = zo(1)+ o(2) o (1) Tf –Tf Tf –Tf 65 60 T '(0) z0 60 (100 129.481) 60.791 56.951 129.481 Because this is a linear problem, this linearly interpolated initial value will yield the correct solution from our spreadsheet using the same value of h = 0.2 (but one should always actually try it out to verify the calculation of the interpolant). 3. Partial Differential Equations [20 points] (a) Classify the following PDE’s as elliptic, parabolic, or hyperbolic and as linear or nonlinear. Show or explain your reasoning. Assume that E, F, D, ψ, and c are positive functions and that ψ < 1. (i) The generalized Poisson equation u u E ( x, y ) F ( x, y) g ( x, y) x x y y (ii) The generalized convection-diffusion equation u u u D ( x ) u ( x, t ) k u ( x, t ) t x x x (iii) The equation governing the behavior of a wake behind a thin plate held fixed in a uniform stream of incompressible viscous fluid so that the plate is edgewise to the flow. [Ref: S. H. Crandall, Engineering Analysis, McGraw-Hill, 1956, Chapter 6.] ENGRD 241 Final Exam (iv) (v) Name (Print): ________________________ Fall 2001 2 1 2 x y The generalized wave equation 2u u c( x) a u f 2 dt x x The biharmonic equation 4w 4w 4w 2 f ( x, y) x 4 x 2y 2 y 4 (b) What auxiliary conditions – and how many of each – are needed to solve (analytically or numerically) the following second-order PDE’s. It is recommended that you use sketches to clarify your answers. (i) Elliptic in 2D space (e.g., Laplace equation) (ii) Parabolic in 1D space (e.g., the heat equation) (iii) Hyperbolic in 1D space (e.g., the wave equation) (a) For the second-order equations, examine the sign of B2 – 4AC in 2u 2u 2u A 2 B C 2 D 0 [C&C pp. 813-814] x xy y (i) A = E, B = 0, C = F B2 – 4AC = –4EF elliptic and linear (ii) A = D, B = C = 0 B2 – 4AC = 0 parabolic and nonlinear from u u' term (iii) A = B = 0, C = 1 B2 – 4AC = 0 parabolic and nonlinear from (iv) (v) (b) (i) (ii) (iii) 1 term A = c, B = 0, C = –1 B2 – 4AC = 4c hyperbolic and linear This is not second-order so we cannot use examination of B2 – 4AC. However, because there are no time derivatives or first or second derivatives of independent variables other than x or y, we deduce that this represents a steady-state problem for a closed 2D domain and is thus elliptic. It is also linear. Need one boundary condition (Dirichlet: u = f; Neumann: u / n = g; or mixed: a u + b u / n = c) on every point on the boundary. Typically, these problems have a closed domain, i.e., a boundary completely surrounding the spatial domain. (Because elliptic equations represent steady-state behavior, initial conditions are not relevant or needed.) Need boundary conditions on both ends of the 1D spatial domain (Dirichlet, Neumann, or mixed), e.g., Dirichlet would be u ( x0 , t ) and u ( x f , t ) specified for all t. Also need initial conditions for the dependent variable over the entire space at the beginning of the time span, e.g., u ( x, 0) . The domain is closed in space but open in future time. Need boundary conditions on both ends of the 1D spatial domain (Dirichlet, Neumann, or mixed) – same as for part b(ii). Also need two initial conditions – the dependent variable and its first derivative with respect to time – over the entire space at the beginning of the time span, e.g., u ( x, 0) (initial displacement) and ENGRD 241 Final Exam Name (Print): ________________________ Fall 2001 u ( x, 0) (initial velocity). The domain is closed in space but open in future time. 4. Partial Differential Equations [15 points] Consider the heat conduction equation in 2 spatial dimensions: 2T 2T T k 2 2 C&C Eq. (30.18) t y x You plan to solve this numerically using the finite difference method and, rather than using the ADI scheme, you will solve using an implicit method and the solution of the 2D spatial matrix equations at each time step. Assume Δx = Δy = h. Write the finite difference equation for a typical interior grid point (in either equation or computational-molecule form) for the simple implicit method. Use the following indices: subscript i for the x-direction grid points, subscript j for the y-direction grid points, and superscript ℓ for the time levels, e.g., Ti , j , and use appropriate additions or subtractions to the indices to indicate adjacent points in space-time. Assume that all values have already been computed up to the time level ℓ. For the simple implicit method we write the spatial operator at time ℓ+1 and the time operator as a backward difference from time ℓ+1 to ℓ. The spatial operator is the 2 operator from C&C Eq. (29.8) written at time ℓ+1 but multiplied by k/h2: 2T 2T k k 2 2 T 1 Ti 1,1j Ti , j11 Ti , j11 4Ti , j1 2 i 1, j y h x The time operator is given in C&C Eq. (30.3) [identical for forward or backward finite-divided difference in time] but with subscripts that account for 2 spatial dimensions: Ti , j1 Ti , j T t t Using the usual notation of k t / h2 , we can combine these to obtain the equation form of the computational molecule, in which all the unknowns are collected on the left-hand side: (1 4 )Ti , j1 Ti 1,1j Ti 1,1j Ti , j11 Ti , j11 Ti , j 5. Rootfinding [15 points] The locations of sampling points for Gaussian Quadrature (sometimes called "GaussLegendre quadrature") are the roots (zeros) of Legendre polynomial. For example, for sixpoint Gaussian Quadrature, the Legendre polynomial of sixth order is 1 P6 ( x) 693x 6 945 x 4 315 x 2 15 48 (Note: All the zeros of the Legendre polynomials are less than one in magnitude and, for polynomials of even order, are symmetrical about the origin.) [Acknowledgment: C. F. Gerald & P. O. Wheatley, Applied Numerical Analysis, Addison-Wesley, 4th Edition, 1989, prob. 1.63. ] In an attempt ENGRD 241 Final Exam Name (Print): ________________________ Fall 2001 to find the sampling point near 0.65 for the sixth-order Legendre polynomial, the following spreadsheet calculations have been performed. A 1 2 3 4 5 B C D E F G H Rootfinding by the Secant Method Please do the following: 1. Define the function, ff(x), in the Visual Basic module for this worksheet 2. Provide initial guesses (need not bound the root). xi-1 = 0.5000 xi = 6 0.8000 3. Provide stopping tolerances: es = 1.00E-05 7 8 max = 9 5 (%) (maximum # of iterations, <35) 10 11 Iter xi-1 f(xi-1) xi f(xi) xi+1 f(xi+1) ea (%) 12 1 2 3 4 5 0.500000000 0.800000000 0.635618849 0.662737817 0.661152650 3.232E-01 -3.918E-01 7.741E-02 -4.806E-03 1.781E-04 0.800000000 0.635618849 0.662737817 0.661152650 0.661209286 -3.918E-01 7.741E-02 -4.806E-03 1.781E-04 3.152E-07 0.635618849 0.662737817 0.661152650 0.661209286 7.741E-02 -4.806E-03 1.781E-04 3.152E-07 2.59E+01 4.09E+00 2.40E-01 8.57E-03 (i) (ii) (iii) 13 14 15 16 For each of the indicated missing results (i) through (iii), write the equation and calculate the value. Use 9 significant figures for values of x. xi 1 xi (i) (ii) (iii) f ( xi )( xi 1 xi ) f ( xi 1 ) f ( xi ) C&C Eq. (6.7) 3.152 107 (0.661152650 0.661209286) 0.661209286 0.661209386 1.781104 3.152 107 9 f ( xi 1 ) (((693xi21 945) xi21 315) xi21 15) / 48 1.469 10 (results may differ due to rounding and differences in pocket calculators) x x 0.661209386 0.661209286 a i 1 i 100% 100 1.512 105% xi 1 0.661209386 6. Systems of Equations [20 points] You are to solve the following set of equations iteratively by the Gauss-Seidel method: ENGRD 241 Final Exam (a) (b) Name (Print): ________________________ Fall 2001 4 0 1 x1 8 A x 1 3 0 x2 6 b 0 1 2 x3 4 Will the Gauss-Seidel method converge for this problem? Justify your answer. The textbook suggests using a trial starting value for the iterative solution of x 0 T (c) (d) (a) 0 0 0 . Suggest an alternative set of starting values that might be closer to the final answers and explain your rationale. Write the three iterative equations you will use in general symbolic form, including proper superscripts on the xi j to indicate the iteration number. Perform (only) two (2) full iterations numerically, and calculate the approximate error of each iteration. A sufficient condition for convergence of the Gauss-Seidel method is given on page 9 of Lecture Notes 3B and on C&C page 293, Eq. (11.10): n aii (b) a j 1 j i ij That is, the system must be diagonally dominant. This set of equations fulfills this condition, so the method will converge. Because of the diagonal dominance, a good first approximate solution is given by xi bi / aii , that is, by neglecting the off-diagonal terms. For this problem, this approximation yields: x 0 T (c) 2 2 2 The Gauss-Seidel equations are given on page 8 of Lecture Notes 3B or by C&C Eqs. (11.5) with appropriate superscripts added to show that the most recent values are used: x1j 1 (b1 a12 x2j a13 x3j ) / a11 x2j 1 (b2 a21 x1j 1 a23 x3j ) / a22 (d) x3j 1 (b3 a31 x1j 1 a32 x2j 1 ) / a33 Use starting values from part (b). [But full credit for correct calculations with any starting values.] 1.5 2 x11 (8 0 2 1 2) / 4 1.5 a 100 33.3% 1.5 x12 (6 11.5 0 2) / 3 1.5 x31 (4 0 1.5 11.5) / 2 1.25 a 1.5 2 100 33.3% 1.5 a 1.25 2 100 60% 1.25 ENGRD 241 Final Exam Name (Print): ________________________ x12 (8 0 1.5 11.25) / 4 1.6875 a x22 (6 11.6875 0 1.25) / 3 1.4375 x32 (4 0 1.6875 11.4375) / 2 1.2813 Fall 2001 1.6875 1.5 100 11.1% 1.6875 a 1.4375 1.5 100 4.3% 1.4375 a 1.2813 1.25 100 2.4% 1.2813 [Converged solution is x 1.6800 1.4400 1.2800 ] T 7. Interpolation and Curve Fitting [20 points] The following data for creep rate, , the time rate at which strain increases, and the corresponding stress, , were obtained from a creep test performed at room temperature on a wire composed of 40% tin, 60% lead, and a solid solder core. Use a power-law, least-squares curve fit of the equation B m to find the values of B and m. [This is based on C&C Problem 20.49, page 561.] Creep rate, min-1 0.0004 0.0011 0.0031 Stress, MPa 5.775 8.577 12.555 Let y = log and x = log . Then when we take logs of the full equation, we obtain the linear equation log log B m log or y a0 a1 x . We can find the intercept and slope by linear regression, that is, by means of C&C Eqs. (17.4) to (17.7). We can arrange the necessary calculations in tabular form as follows: i xi = log 1 0.76155 2 0.93232 3 1.09882 Σ 2.79269 Then m a1 n xi yi xi yi n x xi 2 i and log B a0 y a1 x 2 yi = log -3.3979 -2.9586 -2.5086 -8.8651 xi2 0.57996 0.86922 1.20740 2.65658 xiyi -2.5877 -2.7584 -2.7565 -8.1026 3(8.1026) 2.79269(8.8651) 2.636 3(2.65658) (2.79269)2 8.8651 2.636(2.79269) 5.4089 3 B 3.900 106 8. Numerical Integration [15 points] The following integral is being evaluated by Gaussian Quadrature with six sampling points. ENGRD 241 Final Exam Name (Print): ________________________ Fall 2001 1 1 x ln dx x 1 x 0 1 I [As an aside, notice that the integrand is singular at x = 1 since ln(2/0) is infinite, and that the value of the integrand is indeterminate (but not singular) at x = 0 since ln(1)/0 = 0/0; however, because Gaussian Quadrature is an open method, it never requires the evaluation of the integrand at the end points of the interval of integration. Acknowledgment: R. W. Hornbeck, Numerical Methods, Quantum Publishers, 1975, prob. 8.13.] The following partial results for this problem have been obtained with a spreadsheet program: A B C D E F 1 Welcome to: Numerical Integration by Gauss Quadrature 2 To use this spreadsheet: 1. Define the integrand, f(x), in a VB macro. 2. Define the Limits of Integration: a= 0.0000 b= 1.0000 3. Define the # of Gauss-Legendre sampling points: p= 6 ( Note: 2 ? # pts. ? 6 ) 3 4 5 6 7 8 9 10 Results: dx = 0.5*(b - a) = sampling pt. xd xi 0.5000 f(xi)*dx 11 pt. # 12 -0.932469514 -0.661209386 -0.238619186 0.238619186 0.661209386 0.0338 0.1694 0.3807 0.6193 1.0004 1.0097 1.0530 1.1689 16 0 1 2 3 4 (i) 17 5 0.932469514 0.9662 13 14 15 (b) (a) wi*f(xi)*dx 0.1714 0.3643 0.4927 0.5469 (ii) 0.171324492 0.360761573 0.467913935 0.467913935 0.360761573 2.1032 0.171324492 0.3603 I= 18 (a) wi (iii) (iv) For each of the indicated missing results (i) through (iv), write the equation and calculate the value. If the exact answer is I = π2/4 = 2.4674011, what is the true relative error of the approximate numerical answer? (i) (ii) (iii) (b a) (b a) xd 1 1(0.661209386) 0.8306 C&C Eq.(22.23) 2 2 1 1 xi 1 1 0.8306 f ( xi ) dx ln ln dx 0.5 1.4328 xi 1 xi 0.8306 1 0.8306 1.4328(0.360761573) = 0.5169 xi ENGRD 241 Final Exam (iv) Name (Print): ________________________ Fall 2001 I wi f ( xi )dx 2.4525 i (b) I I 2.4674011 2.4525 t t 100% 100 0.604% It 2.4674011 9. Errors and Approximation [15 points] Discuss briefly the two principal contributions to total numerical error in computational approximations. From what do each of these arise, i.e., what is the source of each? Describe how the interplay of these different sources of error can sometimes be used to estimate an “optimal” step size for a numerical method. Use a sketch and an example; for instance, the example could be numerical differentiation (in very general terms). The two principal contributions to numerical error are truncation and roundoff. Truncation arises from using series approximations in place of an exact mathematical procedure (e.g., finite divided differences in place of differentiation, summation in place of integration). Roundoff arises from the discrete and finite arithmetic in digital computation, that is, from only a fixed number of significant figures in the mantissa, from critical arithmetic (e.g., subtraction of two numbers of nearly equal value), and from the gaps between representable numbers. The two errors tend to have opposite trends: truncation errors become smaller with smaller step size, and roundoff errors become more dominant with very small step sizes. This can be shown schematically on a plot of log error vs. log step size as in C&C Figure 4.8, page 94. The fact that the total error, i.e., the sum of the truncation error and the roundoff error, may have a minimum suggests that one attempt to select a step size (h) at or near the minimum of the total error (T). dT 0 estimate of “optimal” h. For That is, T(h) = truncation + roundoff = C(h) + R(h), and dh example, in numerical differentiation, a truncation error of O(hn) gives C(h) = Ahn, while roundoff error of the mth order derivative gives R(h) = B/hm. Thus T = Ahn + B/hm clearly indicate the pattern depicted in C&C Figure 4.8.