CMPS 251 Homework Assignment 6 Solution, Fall 2015

American University of Beirut · Numerical Computing · 5 pages · with solution

All CMPS 251 files
CMPS 251 Homework Assignment 6 Solution, Fall 2015, page 1

Stuck on a question? A tutor can walk you through it.

CMPS 251 Homework Assignment 6 Solution, Fall 2015, page 2 CMPS 251 Homework Assignment 6 Solution, Fall 2015, page 3 CMPS 251 Homework Assignment 6 Solution, Fall 2015, page 4 CMPS 251 Homework Assignment 6 Solution, Fall 2015, page 5

More CMPS 251 files

Show the text of this homework
CMPS 251 Assignment 6-Solution Problem 1 n=1 This corresponds to Euler's method 𝑦(𝑡 + ℎ) = 𝑦(𝑡) + ℎ𝑓(𝑡, 𝑦(𝑡)) = 𝑦(𝑡) + ℎ(𝑦2(𝑡) + 𝑦(𝑡)𝑒𝑡 n=2 𝑦′′ = 2𝑦𝑦′ + 𝑦′𝑒𝑡 + 𝑦𝑒𝑡 𝑦(𝑡 + ℎ) = 𝑦(𝑡) + ℎ𝑦′(𝑡) + ℎ2 2 𝑦′′(𝑡) n=3: 𝑦′′′ = 2(𝑦′)2 + 2𝑦𝑦′′ + 𝑦′′𝑒𝑡 + 𝑦′𝑒𝑡 + 𝑦′𝑒𝑡 + 𝑦𝑒𝑡 𝑦(𝑡 + ℎ) = 𝑦(𝑡) + ℎ𝑦′(𝑡) + ℎ2 2 𝑦′′(𝑡) + ℎ3 6 𝑦′′′(𝑡) To find y(0.02), let t=0 h=0.02, 𝑦′(0) = 𝑦2(0) + 𝑦(0)𝑒0 = 2 𝑦′′(0) = 2𝑦(0)𝑦′(0) + 𝑦′(0)𝑒0 + 𝑦(0)𝑒0 = 7 𝑦′′′(0) = 34 Thus, 𝑛 = 1, 𝑦(0.02) = 1 + 0.02(2) = 1.04 𝑛 = 2, 𝑦(0.02) = 1 + 0.02(2) + (0.02)2 2 (7) = 1.0414 𝑛 = 3, 𝑦(0.02) = 1 + 0.02(2) + (0.02)2 2 (7) + (0.02)3 6 (34) = 1.0414453 Problem 2 The implicit solution is found in two steps using Heun's method where we calculate x(t+h) as 𝑥(𝑡 + ℎ) = 𝑥(𝑡) + ℎ 2 (𝑓(𝑡, 𝑥(𝑡)) + 𝑓(𝑡 + ℎ, 𝑥(𝑡) + ℎ𝑓(𝑡, 𝑥(𝑡))) This is done in two steps 𝑝𝑘+1 = 𝑥𝑘 + ℎ𝑓(𝑡𝑘, 𝑥𝑘), 𝑡𝑘+1 = 𝑡𝑘 + ℎ 𝑥𝑘+1 = 𝑥𝑘 + ℎ 2 (𝑓(𝑡𝑘, 𝑥𝑘) + 𝑓(𝑡𝑘+1, 𝑝𝑘+1)) This is illustrated in the following figure Heun's method involves two steps to calculate each solution point and has an error in the order of 𝑂(ℎ2) Problem 3 Using the Runge-Kutta method, we get the following values, 𝑥 = [2.0000 2.0564 2.4147 3.1902]; Using Euler's Method we get 𝑥 = [2.0000 2.0000 2.1715 2.8033] Actual Solution 𝑥 = [2.0000 2.0564 2.4144 3.1897]; Problem 4 The system can be written as { 𝑥′ = 𝑦 𝑥(0) = −1 𝑦′ = 𝑓(𝑡, 𝑥, 𝑦) = −2𝑦 − 𝑥 𝑦(0) = 0.2 We use the equations as given in the assignment 𝑥1 = 𝑥(0.5) = 𝑥(0) + 0.5. 𝑦(0) = −1 + 0.5 ⋅ 0.2 = −0.9 𝑦1 = 𝑦(0.5) = 𝑦(0) + 0.5 ⋅ (−2𝑦(0) − 𝑥(0)) = 0.5 𝑖 𝑡𝑖 𝑥𝑖 𝑦𝑖 0 0 -1 0.2 1 0.5 -0.9 0.5 2 1 -0.65 0.45 Now to solve the BVP, we apply this method twice 𝑖 𝑡𝑖 𝑥𝑖 𝑦𝑖 0 0 0 0 1 0.5 0 0 2 1 0 -1 𝑖 𝑡𝑖 𝑥𝑖 𝑦𝑖 0 0 0 1 1 0.5 0.5 1 2 1 1 1 Using a linear shooting method 𝜆 = 𝛽−𝑥2(𝑏) 𝑥1(𝑏)−𝑥2(𝑏) = 2−𝑥2(1) 𝑥1(1)−𝑥2(1) = 2−1 0−1 = −1 The solution can be computed as follows 𝑖 𝑥1(𝑡𝑖) 𝑥2(𝑡𝑖) 𝑥(𝑡𝑖) = 𝜆𝑥1(𝑡𝑖) + (1 − 𝜆)𝑥2(𝑡𝑖) 0 0 0 0 1 0 0.5 1 2 0 1 2=𝛽 For h=0.0001, the exact solution coincides with the obtained x(t) Problem 5 For h=1/2, we have one point to determine 1 0.25 (𝑥0 − 2𝑥1 + 𝑥2) = −4𝑡1 + 4𝑥1, 𝑥0 = 0 𝑥2 = 2 4(2 − 2𝑥1) = −2 + 4𝑥1 We get that 𝑥1 = 5 6 = 0.83333333 For h=1/4, we have three points to determine 𝑥1, 𝑥2, 𝑥3 { 16(𝑥0 − 2𝑥1 + 𝑥2) = −4𝑡1 + 4𝑥1 16(𝑥1 − 2𝑥2 + 𝑥3) = −4𝑡2 + 4𝑥2 16(𝑥2 − 2𝑥3 + 𝑥4) = −4𝑡3 + 4𝑥3 This leads to the following system in three unknowns { −36𝑥1 + 16𝑥2 = −4𝑡1 − 16𝑥0 = −4(0.25) − 0 = −1 16𝑥1 − 36𝑥2 + 16𝑥3 = −4𝑡2 = −2 16𝑥2 − 36𝑥3 = −4𝑡3 − 16𝑥4 = −4(0.75) − 32 = −36 Solving the system yields 𝑥1 = 0.3951, 𝑥2 = 0.8265, 𝑥3 = 1.3396 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 -1 -0.5 0 0.5 1 1.5 2 t Exact Solution x(t) x1(t) x2(t) The extrapolation is the same as the Richardson extrapolation 𝑥(0.5) = 4(0.8265) − 0.8333 3 = 0.8242 Problem 6 Part a Using the continuity of S −𝑎 + 𝑏 − 𝑐 + 𝑑 = −1 𝑎 + 𝑏 + 𝑐 + 𝑑 = 1 continuity of S' 3𝑎 − 2𝑏 + 𝑐 = −1 3𝑎 + 2𝑏 + 𝑐 = 1 continuity of S'' −6𝑎 + 2𝑏 = 0 6𝑎 + 2𝑏 = 0 Natural Spline condition (always valid since second derivative is 0) Last set of equations is satisfied for 𝑎 = 0; 𝑏 = 0 Replacing in the previous equations shows that it is impossible to find a,b,c,d such that it is a natural cubic spline. Part b Using the algorithm presented in the slides we get the following 𝑑 = [0 42.5 − 30 20 − 25]; 𝑄 = { 85(𝑥 − 14)2 32 + 32 𝑥 ∈ [14; 22] 85𝑥 2 − 145(𝑥 − 22)2 32 − 445 𝑥 ∈ [22; 30] 25(𝑥 − 30)2 8 − 30𝑥 + 1440 𝑥 ∈ [30; 38] 20𝑥 − 45(𝑥 − 38)2 16 − 260 𝑥 ∈ [38; 46] A speed of 24 mph falls into the second interval so Q(24)=556.875. Q(35)=468.125