Math 128A Spring 2003 Week 10 Solutions Burden & Faires §5.4: 1a, 3a, 11a, 15, 17 Burden & Faires §5.5: 1a (the equation should be y 0 = te3t − 2y), 5 Burden & Faires §5.4. Runge-Kutta Methods 1. Use the Modified Euler method to approximate the solution to the following intial-value problem, and compare the result to the actual value. a. y 0 = te3t − 2y, 0 ≤ t ≤ 1, actual solution y(t) = Solution. y(0) = 0, with h = 0.5; 1 1 1 3t te − e3t + e−2t . 5 25 25 a. Using the modified Euler method, we have: t0 w0 = = y(t0 ) = t1 = = w1 = = = = y(t1 ) = t2 w2 = = = = = y(t2 ) = = 0.0 0.0000000 1 1 1 (0.0)e3(0.0) − e3(0.0) + e−2(0.0) 5 25 25 0.0000000 0.5 h w0 + [f (t0 , w0 ) + f (t1 , w0 + hf (t0 , w0 ))] 2 0.0000000 + 0.25[f (0.0, 0.0000000) + f (0.5, 0.0000000 + 0.5f (0.0, 0.0000000))] 0.25[0.5e1.5 ] 0.5602111 1 1 1 (0.5)e3(0.5) − e3(0.5) + e−2(0.5) 5 25 25 0.2836165 1.0 0.5602111 + 0.25[f (0.5, 0.5602111) + f (1.0, 0.5602111 + 0.5f (0.5, 0.5602111))] 0.5602111 + 0.25[0.5e1.5 − 2(0.5602111) + 1.0e3.0 − 2(0.5602111 + 0.5(0.5e1.5 −2(0.5602111)))] 5.3014898 1 1 1 (1.0)e3(1.0) − e3(1.0) + e−2(1.0) 5 25 25 3.2190993 3. Repeat Exercise 1 using the Midpoint method. 1 Solution. a. Using the Midpoint method, we have: t0 = 0.0 w0 = 0.0000000 y(t0 ) = 0.0000000 t1 = 0.5 h h w1 = w0 + hf t0 + , w0 + f (t0 , w0 ) 2 2 = 0.0000000 + 0.5f (0.25, 0.0000000 + 0.25f (0.0, 0.0000000)) = 0.5[(0.25)e0.75 − 2(0.25)(0)] = 0.2646250 y(t1 ) = 0.2836165 t2 = 1.0 h h w2 = w1 + hf t1 + , w1 + f (t1 , w1 ) 2 2 = 0.2646250 + 0.5f (0.75, 0.2646250 + 0.25f (0.5, 0.2646250)) = 0.2646250 + 0.5 (0.75)e2.25 − 2 0.2646250 + 0.25 (0.5)e1.5 − 2(0.2646250) = 3.1300023 y(t2 ) = 3.2190993 11. Use the Runge-Kutta method of order four to approximate the solution to the following initial-value problem, and compare the result to the actual value. a. y 0 = y/t − (y/t)2 , 1 ≤ t ≤ 2, y(1) = 1, with h = 0.1; actual solution y(t) = t/(1 + ln t). Solution. Applying the Runge-Kutta method of order four we obtain the following results. ti 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 wi 1.0000000 1.0042815 1.0149520 1.0298133 1.0475336 1.0672620 1.0884323 1.1106547 1.1336532 1.1572281 1.1812319 y(ti ) 1.0000000 1.0042817 1.0149523 1.0298137 1.0475339 1.0672624 1.0884327 1.1106551 1.1336536 1.1572284 1.1812322 15. The irreversible chemical reaction in which two molecules of solid potassium dichromate (K2 Cr2 O7 ), two molecules of water (H2 O), and three atoms os solid sulfur (S) combine to yield three molecules of gas sulfur dioxide (SO2 ), four molecules of solid potassium hydroxide (KOH), and two molecules of solid chromic oxide (Cr2 O3 ) can be represented symbolically by the stoichiometric equation: 2K2 Cr2 O7 + 2H2 O + 3S −→ rKOH + 2Cr2 O3 + 3SO2 . 2 If n1 molecules of K2 Cr2 O7 , n2 molecules of H2 O, and n3 molecules of S are originally available, the following differential equation describes the amount x(t) of KOH after time t: 3 dx x 2 3x x 2 n2 − n3 − , = k n1 − dt 2 2 4 where k is the velocity constant of the reaction. If k = 6.22 × 10−19 , n1 = n2 = 2 × 103 , and n3 = 3 × 103 , how many units of potassium hydroxide will have been formed after 0.2 s? Solution. Running the Runge-Kutta method with 100 subintervals gives 2079.4153 and with 1000 subintervals gives 2079.4083753, so we see that there will be 2079 units of potassium hydroxide. 17. The Runga-Kutta method of order four can be written in the form w0 wi+1 = α, = wi + h h f (ti , wi ) + f (ti + α1 h, wi + δ1 hf (ti , wi )) 6 3 h + f (ti + α2 h, wi + δ2 hf (ti + γ2 h, wi + γ3 hf (ti , wi ))) 3 h + f (ti + α3 h, wi + δ3 hf (ti + γ4 h, wi + γ5 hf (ti + γ6 h, wi + γ7 hf (ti , wi )))). 6 Find the values of the constants α1 , α2 , α3 , δ1 , δ2 , δ3 , γ2 , γ3 , γ4 , γ5 , γ6 , and γ7 . Solution. w0 k1 k2 k3 k4 wi+1 = α = hf (ti , wi ) h 1 = hf ti + , wi + k1 2 2 1 h = hf ti + , wi + hf (ti , wi ) 2 2 h 1 = hf ti + , wi + k2 2 2 h 1 h 1 = hf ti + , wi + hf ti + , wi + hf (ti , wi ) 2 2 2 2 = hf (ti+1 , wi + k3 ) h 1 h 1 = hf ti+1 , wi + hf ti + , wi + hf ti + , wi + hf (ti , wi ) 2 2 2 2 1 h 1 = wi + hf (ti , wi ) + 2hf ti + , wi + hf (ti , wi ) 6 2 2 h 1 h 1 +2hf ti + , wi + hf ti + , wi + hf (ti , wi ) 2 2 2 2 h 1 h 1 +hf ti+1 , wi + hf ti + , wi + hf ti + , wi + hf (ti , wi ) 2 2 2 2 h h h 1 = wi + f (ti , wi ) + f ti + , wi + hf (ti , wi ) 6 3 2 2 h h 1 h 1 + f ti + , wi + hf ti + , wi + hf (ti , wi ) 3 2 2 2 2 h h 1 h 1 + f ti+1 , wi + hf ti + , wi + hf ti + , wi + hf (ti , wi ) 6 2 2 2 2 3 Thus we have α1 = 12 δ1 = 12 γ2 = 21 γ5 = 12 α2 = 21 δ2 = 12 γ3 = 21 γ6 = 21 α3 = 1 δ3 = 1 γ4 = 21 γ7 = 21 Burden & Faires §5.5. Error Control and the Runge-Kutta Method 1. Use the Runge-Kutta-Fehlberg method with tolerance TOL = 10−4 , hmax = 0.25, and hmin = 0.05 to approximate the solution to the following initial-value problem. Compare the results to the actual values. a. y 0 = te3t − 2y, Solution. 0 ≤ t ≤ 1, y(0) = 0; actual solution y(t) = 1 3t 1 1 te − e3t + e−2t . 5 25 25 a. Running the Runge-Kutta-Fehlberg method we get the following results. ti 0.0000000 0.2093900 0.3832972 0.5610469 0.7106840 0.8387744 0.9513263 1.0000000 wi 0.0000000 0.0298184 0.1343260 0.4016438 0.8708372 1.5894061 2.6140226 3.2190497 hi 0.0000000 0.1739072 0.1739072 0.1777496 0.1496371 0.1280905 0.1125519 0.0486737 y(ti ) 0.0000000 0.0298337 0.1343488 0.4016860 0.8708882 1.5894600 2.6140771 3.2190993 5. In the theory of the spread of contagious disease, a relatively elementary differential equation can be used to predict the number of infective individuals in the population at any time, provided appropriate simplification assumptions are made. In particular, let us assume that all individuals in a fixed poplulation have an equally likely chance of being infected and once infected remain in that state. Suppose x(t) denotes the number of susceptible individuals at time t and y(t) denotes the number of infectives. It is reasonable to assume that the rate at which the number of infectives changes is proportional to the product of x(t) and y(t) since the rate depends on both the number of infectives and the number of susceptibles present at that time. If the population is large enough to assume that x(t) and y(t) are continuous variables, the problem can be expressed y 0 (t) = kx(t)y(t), where k is a constant and x(t) + y(t) = m, the total population. This equation can be rewritten involving only y(t) as y 0 (t) = k(m − y(t))y(t). a. Assuming that m = 100, 000, y(0) = 1000, k = 2 × 10−6 , and that time is measured in days, find an approximation to the number of infective individuals at the end of 30 days. b. The differential equation in part (a) is called a Bernoulli equation and it can be transformed into a linear differential equation in u(t) = (y(t))−1 . Use this technique to find the exact solution to the equation, under the same assumptions as in part (a), and compare the true value of y(t) to the approximation given there. What is limt→∞ y(t)? Does this agree with your intuition? 4 Solution. a. Running Runge-Kutta-Fehlberg with a tolerance of 10−4 , minimum mesh size of 0.1 and maximum mesh size of 1.0, we get y(30) = 80295.719. b. Applying the substitution, we get the differential equation: d(u(t)−1 ) = k m − u(t)−1 u(t)−1 dt 1 u0 (t) 1 = k m − − [u(t)]2 u(t) u(t) u0 (t) = −k(mu(t) − 1) = −kmu(t) + k 1 u(t) = ce−kmt + m 1 u(0) = c + m 1 c = u(0) − m 1 1 e−kmt + . u(t) = u(0) − m m When m = 100000, u(0) = 1 , 1000 k = 2 × 10−6 , then the solution is given by u(t) = = y(t) = 1 1 1 − e−0.2t + 1000 100000 100000 99e−0.2t + 1 × 10−5 105 99e−0.2t + 1 Thus, we have y(30.0) = 80295.715 and lim y(t) = 105 = m. t→∞ It would be expected that eventually everyone would be infected. 5