The Computable Differential Equation Lecture ... - Bruce E. Shapiro
The Computable Differential Equation Lecture ... - Bruce E. Shapiro The Computable Differential Equation Lecture ... - Bruce E. Shapiro
98 CHAPTER 5. RUNGE-KUTTA METHODS Figure 5.4: Comparison of absolute error at t = 1 as a function of step size for the test problem. Dashed Line: Euler’s Method; Solid Line: Runge-Kutta 4-stage method k 4 = y 0 + hf(t 1/2 , k 3 ) (5.81) = 1 + (0.5)(1.3125) = 1.65625 (5.82) y 1 = y 0 + h 6 (f(t 0, k 1 ) + 2f(t 1/2 , k 2 ) + 2f(t 1/2 , k 3 ) + f(t 1 , k 4 )) (5.83) = y 0 + h 6 (k 1 + 2k 2 + 2k 3 + k 4 ) (5.84) = 1 + .5 1 + 2(1.25) + 2(1.3125) + 1.65625 = 1.64844 (5.85) 6 Thus the numerical approximation to y(0.5) is y 1 ≈ 1.64844. For the second step, k 1 = y 1 = 1.64844 (5.86) k 2 = y 1 + h 2 f(t 1, k 1 ) (5.87) = 1.64844 + (0.25)(1.64844) = 2.06055 (5.88) k 3 = y 1 + h 2 f(t 1.5, k 2 ) (5.89) = 1.64844 + (0.25)(2.06055) = 2.16358 (5.90) k 4 = y 1 + hf(t 1.5 , k 3 ) (5.91) = 1.64844 + (0.5)(2.16358) = 2.73023 (5.92) y 2 = y 1 + h 6 (k 1 + 2k 2 + 2k 3 + k 4 ) (5.93) = 1.64844 + .5 1.64844 + 2(2.06055) + 2(2.16358) + 2.73023 = 2.71735 (5.94) 6 Math 582B, Spring 2007 California State University Northridge c○2007, B.E.Shapiro Last revised: May 23, 2007
CHAPTER 5. RUNGE-KUTTA METHODS 99 This gives us a numerical approximation of y(1) ≈ 2.71735, and error of approximately 0.034% (the exact value is e ≈ 2.71828. By comparison, a forward Euler computation with the same step size will yield a numerical result of 2.25, an error approximately 17%. Since it is an explicit method, the Runge-Kutta 4-stage method is very easy to implement in a computer, even though calculations are very tedious to do by hand. Here is a Mathematica implementation. RK4[f , {t0 , y0 }, h , tmax ] := Module[ {k1, k2, k3, k4, t, yval, r}, r = {{t0, y0}}; yval = y0; For[t = t0, t < tmax, t += h, k1 = yval; k2 = yval + (h/2) f[t, k1]; k3 = yval + (h/2)f[t + h/2, k2]; k4 = yval + h f[t + h/2, k3]; yval = yval + (h/6) *(f[t, k1] + 2f[t + h/2, k2] + 2 + h/2, k3] + f[t + h, k4]); AppendTo[r, {t + h, yval}]; ]; Return[r]; ] f[t 5.4 General Form of Runge-Kutta Methods The general form of the s-stage Runge-Kutta Method is s∑ y n = y n−1 + h b i K i (5.95) i=1 where ⎛ K i = f ⎝t n−1 + c i h, y n−1 + h s∑ j=1 a ij K j ⎞ ⎠ (5.96) and c i = s∑ a ij (5.97) j=1 The coefficients a ij , b j are chosen by comparing the method with a Taylor series expansion and choosing values that cancel specific terms in the error. There are many c○2007, B.E.Shapiro Last revised: May 23, 2007 Math 582B, Spring 2007 California State University Northridge
- Page 53 and 54: CHAPTER 3. APPROXIMATE SOLUTIONS 47
- Page 55 and 56: CHAPTER 3. APPROXIMATE SOLUTIONS 49
- Page 57 and 58: CHAPTER 3. APPROXIMATE SOLUTIONS 51
- Page 59 and 60: CHAPTER 3. APPROXIMATE SOLUTIONS 53
- Page 61 and 62: CHAPTER 3. APPROXIMATE SOLUTIONS 55
- Page 63 and 64: CHAPTER 3. APPROXIMATE SOLUTIONS 57
- Page 65 and 66: CHAPTER 3. APPROXIMATE SOLUTIONS 59
- Page 67 and 68: CHAPTER 3. APPROXIMATE SOLUTIONS 61
- Page 69 and 70: CHAPTER 3. APPROXIMATE SOLUTIONS 63
- Page 71 and 72: CHAPTER 3. APPROXIMATE SOLUTIONS 65
- Page 73 and 74: CHAPTER 3. APPROXIMATE SOLUTIONS 67
- Page 75 and 76: Chapter 4 Improving on Euler’s Me
- Page 77 and 78: CHAPTER 4. IMPROVING ON EULER’S M
- Page 79 and 80: CHAPTER 4. IMPROVING ON EULER’S M
- Page 81 and 82: CHAPTER 4. IMPROVING ON EULER’S M
- Page 83 and 84: CHAPTER 4. IMPROVING ON EULER’S M
- Page 85 and 86: CHAPTER 4. IMPROVING ON EULER’S M
- Page 87 and 88: CHAPTER 4. IMPROVING ON EULER’S M
- Page 89 and 90: CHAPTER 4. IMPROVING ON EULER’S M
- Page 91 and 92: CHAPTER 4. IMPROVING ON EULER’S M
- Page 93 and 94: CHAPTER 4. IMPROVING ON EULER’S M
- Page 95 and 96: Chapter 5 Runge-Kutta Methods 5.1 T
- Page 97 and 98: CHAPTER 5. RUNGE-KUTTA METHODS 91 w
- Page 99 and 100: CHAPTER 5. RUNGE-KUTTA METHODS 93 w
- Page 101 and 102: CHAPTER 5. RUNGE-KUTTA METHODS 95 5
- Page 103: CHAPTER 5. RUNGE-KUTTA METHODS 97 F
- Page 107 and 108: CHAPTER 5. RUNGE-KUTTA METHODS 101
- Page 109 and 110: CHAPTER 5. RUNGE-KUTTA METHODS 103
- Page 111 and 112: CHAPTER 5. RUNGE-KUTTA METHODS 105
- Page 113 and 114: CHAPTER 5. RUNGE-KUTTA METHODS 107
- Page 115 and 116: CHAPTER 5. RUNGE-KUTTA METHODS 109
- Page 117 and 118: CHAPTER 5. RUNGE-KUTTA METHODS 111
- Page 119 and 120: CHAPTER 5. RUNGE-KUTTA METHODS 113
- Page 121 and 122: CHAPTER 5. RUNGE-KUTTA METHODS 115
- Page 123 and 124: Chapter 6 Linear Multistep Methods
- Page 125 and 126: CHAPTER 6. LINEAR MULTISTEP METHODS
- Page 127 and 128: CHAPTER 6. LINEAR MULTISTEP METHODS
- Page 129 and 130: CHAPTER 6. LINEAR MULTISTEP METHODS
- Page 131 and 132: CHAPTER 6. LINEAR MULTISTEP METHODS
- Page 133 and 134: CHAPTER 6. LINEAR MULTISTEP METHODS
- Page 135 and 136: CHAPTER 6. LINEAR MULTISTEP METHODS
- Page 137 and 138: CHAPTER 6. LINEAR MULTISTEP METHODS
- Page 139 and 140: CHAPTER 6. LINEAR MULTISTEP METHODS
- Page 141 and 142: Chapter 7 Delay Differential Equati
- Page 143 and 144: CHAPTER 7. DELAY DIFFERENTIAL EQUAT
- Page 145 and 146: CHAPTER 7. DELAY DIFFERENTIAL EQUAT
- Page 147 and 148: CHAPTER 7. DELAY DIFFERENTIAL EQUAT
- Page 149 and 150: CHAPTER 7. DELAY DIFFERENTIAL EQUAT
- Page 151 and 152: CHAPTER 7. DELAY DIFFERENTIAL EQUAT
- Page 153 and 154: CHAPTER 7. DELAY DIFFERENTIAL EQUAT
98 CHAPTER 5. RUNGE-KUTTA METHODS<br />
Figure 5.4: Comparison of absolute error at t = 1 as a function of step size for<br />
the test problem. Dashed Line: Euler’s Method; Solid Line: Runge-Kutta 4-stage<br />
method<br />
k 4 = y 0 + hf(t 1/2 , k 3 ) (5.81)<br />
= 1 + (0.5)(1.3125) = 1.65625 (5.82)<br />
y 1 = y 0 + h 6 (f(t 0, k 1 ) + 2f(t 1/2 , k 2 ) + 2f(t 1/2 , k 3 ) + f(t 1 , k 4 )) (5.83)<br />
= y 0 + h 6 (k 1 + 2k 2 + 2k 3 + k 4 ) (5.84)<br />
= 1 + .5 1 + 2(1.25) + 2(1.3125) + 1.65625 = 1.64844 (5.85)<br />
6<br />
Thus the numerical approximation to y(0.5) is y 1 ≈ 1.64844. For the second<br />
step,<br />
k 1 = y 1 = 1.64844 (5.86)<br />
k 2 = y 1 + h 2 f(t 1, k 1 ) (5.87)<br />
= 1.64844 + (0.25)(1.64844) = 2.06055 (5.88)<br />
k 3 = y 1 + h 2 f(t 1.5, k 2 ) (5.89)<br />
= 1.64844 + (0.25)(2.06055) = 2.16358 (5.90)<br />
k 4 = y 1 + hf(t 1.5 , k 3 ) (5.91)<br />
= 1.64844 + (0.5)(2.16358) = 2.73023 (5.92)<br />
y 2 = y 1 + h 6 (k 1 + 2k 2 + 2k 3 + k 4 ) (5.93)<br />
= 1.64844 + .5 1.64844 + 2(2.06055) + 2(2.16358) + 2.73023 = 2.71735 (5.94)<br />
6<br />
Math 582B, Spring 2007<br />
California State University Northridge<br />
c○2007, B.E.<strong>Shapiro</strong><br />
Last revised: May 23, 2007