July 2013 Chapter 25 Runge-Kutta Methods أو بالبريد اإللكتروني9 4444 260 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy , eng-hs.neteng-hs.com شرح ومسائل محلولة مجانا بالموقعين [email protected] 9 4444 260 حمادة شعبان.م July 2013 This chapter is devoted to solving ordinary differential equations of the form 𝑑𝑦 𝑑𝑥 = 𝑓(𝑥, 𝑦) We can use a numerical method to solve such an equation for the velocity of the falling parachutist. The method is of the general form New value = old value + slope × step size or, in mathematical terms, 𝑦𝑖+1 = 𝑦𝑖 + ∅ℎ According to this equation, the slope estimate of ∅ is used to extrapolate from an old value 𝑦𝑖 to a new value 𝑦𝑖+1 over a distance h (next figure). All one-step methods can be expressed in this general form, with the only difference being the manner in which the slope is estimated. As in the falling parachutist problem, the simplest approach is to use the differential equation to estimate the slope in the form of the first derivative at xi. أو بالبريد اإللكتروني9 4444 260 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy , eng-hs.neteng-hs.com شرح ومسائل محلولة مجانا بالموقعين [email protected] 9 4444 260 حمادة شعبان.م July 2013 25.1 Euler’s Method The first derivative provides a direct estimate of the slope at 𝑥𝑖 (next figure) ∅ = 𝑓(𝑥𝑖 , 𝑦𝑖 ) where 𝑓(𝑥𝑖 , 𝑦𝑖 ) is the differential equation evaluated at 𝑥𝑖 and 𝑦𝑖 . This estimate can be substituted into 𝑦𝑖+1 = 𝑦𝑖 + 𝑓(𝑥𝑖 , 𝑦𝑖 )ℎ (25.2) This formula is referred to as Euler’s Method. A new value of y is predicted using the slope (equal to the first derivative at the original value of x) to extrapolate linearly over the step size h. (previous figure) احجز خمسه وأربعون دقيقه فى جدول . أعمالك كل أسبوع لالسترخاء العميق أو بالبريد اإللكتروني9 4444 260 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy , eng-hs.neteng-hs.com شرح ومسائل محلولة مجانا بالموقعين [email protected] 9 4444 260 حمادة شعبان.م July 2013 EXAMPLE 25.1 Euler’s Method Problem Statement: Use Euler’s method to numerically integrate 𝑑𝑦 𝑑𝑥 = −2𝑥 3 + 12𝑥 2 − 20𝑥 + 8.5 from x = 0 to x = 4 with a step size of 0.5. The initial condition at x = 0 is y = 1. Recall that the exact solution is given by 𝑦 = −0.5𝑥 4 + 4𝑥 3 + 10𝑥 2 − 8.5𝑥 + 1 Solution: Equation (25.2) can be used to implement Euler’s Method: 𝑦(0.5) = 𝑦(0) + 𝑓(0, 1) 0.5 where y(0) = 1 and the slope estimate at x = 0 is 𝑓(0, 1) = −2(0)3 + 12(0)2 − 20(0) + 8.5 = 8.5 𝑦(0.5) = 1.0 + 8.5(0.5) = 5.25 The true solution at x = 0.5 is 𝑦 = −0.5(0.5)4 + 4(0.5)3 − 10(0.5)2 − 8.5(0.5) + 1 = 3.21875 𝐸𝑡 = 𝑡𝑟𝑢𝑒 − 𝑎𝑝𝑝𝑟𝑜𝑥𝑖𝑚𝑎𝑡𝑒 = 3.21875 − 5.25 = −2.03125 Or, expressed as percent relative error, εt = -63.1%. For the second step, 𝑦(1) = 𝑦(0.5) + 𝑓(0.5, 5.25) = 5.25 + [−2(0.5)3 + 12(0.5)2 − 20(0.5) + 8.5]0.5 = 5.875 The true solution at x = 1.0 is 3.0, and therefore, the percent relative error is -95.8%. The computation is repeated, and the results are compiled in the next table and the next figure. Note that the error can be reduced by using a smaller step size مصااااابيف الفلوريسااااون الحدي ااااة تااااوفر مما تستهلكه المصابيف التقليدية%80 أو بالبريد اإللكتروني9 4444 260 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy , eng-hs.neteng-hs.com شرح ومسائل محلولة مجانا بالموقعين [email protected] 9 4444 260 حمادة شعبان.م July 2013 25.2 Improvements of Euler’s Method A fundamental source of error in Euler’s method is that the derivative at the beginning of the interval is assumed to apply across the entire interval. Two simple modifications are available to help overcome this shortcoming. Both modifications actually belong to a larger class of solution techniques called Runge-Kutta methods. إذا كان هم الربان المحافظة فسفينته،على سالمه السفينة .لن تبرح الميناء أو بالبريد اإللكتروني9 4444 260 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy , eng-hs.neteng-hs.com شرح ومسائل محلولة مجانا بالموقعين [email protected] 9 4444 260 حمادة شعبان.م July 2013 However, because they have a very straightforward graphical interpretation, we will present them prior to their formal derivation as Runge-Kutta methods. 25.2.1 Heun’s Method One method to improve the estimate of the slope involves the determination of two derivatives for the interval – one at the initial point and another at the end point. The two derivatives are then averaged to obtain an improved estimate of the slope for the entire interval. This approach, called Heun’s method, is shown graphically in the next figure. اقبااال الحاااق ولاااو ممااان تكرهاااه وابغض الباطل ولو من صديق أو بالبريد اإللكتروني9 4444 260 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy , eng-hs.neteng-hs.com شرح ومسائل محلولة مجانا بالموقعين [email protected] 9 4444 260 حمادة شعبان.م July 2013 Recall that in Euler’s methods, the slope at the beginning of an interval 𝑦𝑖′ = 𝑓(𝑥𝑖 , 𝑦𝑖 ) is used to extrapolate linearly to 𝑦𝑖+1 : 0 𝑦𝑖+1 = 𝑦𝑖 + 𝑓(𝑥𝑖 , 𝑦𝑖 )ℎ For the standard Euler method we would stop at this point. 0 However, in Heun’s method the 𝑦𝑖+1 calculated in the previous equation is not the final answer, but an intermediate prediction. This is why we have distinguished it with a superscript 0. The previous equation is called a predictor equation. It provided an estimate of yi+1 that allows the calculation of an estimated slope at the end of the interval: ′ 0 𝑦𝑖+1 = 𝑓(𝑥𝑖+1 , 𝑦𝑖+1 ) Thus, the two slopes can be combined to obtain an average slope for the interval: ′ 𝑦̅ = ′ 𝑦𝑖′ + 𝑦𝑖+1 2 = 0 𝑓(𝑥𝑖 , 𝑦𝑖 )+ 𝑓(𝑥𝑖+1 , 𝑦𝑖+1 ) 2 This average slope is then used to extrapolate linearly from 𝑦𝑖 to 𝑦𝑖+1 using Euler’s method: 𝑦𝑖+1 = 𝑦𝑖 + 0 𝑓(𝑥𝑖 , 𝑦𝑖 )+ 𝑓(𝑥𝑖+1 , 𝑦𝑖+1 ) 2 which is called a corrector equation. ℎ ،إن أردت أن تعرف نفسك جيدا بمجرد استيقاظك تذكر ما كنت تحلم به فهذا هو أنت أو بالبريد اإللكتروني9 4444 260 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy , eng-hs.neteng-hs.com شرح ومسائل محلولة مجانا بالموقعين [email protected] 9 4444 260 حمادة شعبان.م July 2013 The Heun method is a predictor-corrector approach. The Heun method is the only one-step predictor-corrector method described in this book. As derived above, it can be expressed concisely as 0 Predictor (previous figure a): 𝑦𝑖+1 = 𝑦𝑖 + 𝑓(𝑥𝑖 , 𝑦𝑖 )ℎ Corrector (figure b): 𝑦𝑖+1 = 𝑦𝑖 + 0 𝑓(𝑥𝑖 ,𝑦𝑖 )+ 𝑓(𝑥𝑖+1 ,𝑦𝑖+1 ) 2 ℎ (25.16) Note that because the previous equation has 𝑦𝑖+1 on both sides of the equal sign, it can be applied in an iterative fashion. That is, an old estimate can be used repeatedly to provide an improved estimate of 𝑦𝑖+1 . The process is shown in the next figure. اجعل لنفسك فترات راحة ،قصيرة خالل وقت دراستك ال تنسى كلمة قصيرة أو بالبريد اإللكتروني9 4444 260 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy , eng-hs.neteng-hs.com شرح ومسائل محلولة مجانا بالموقعين [email protected] 9 4444 260 حمادة شعبان.م July 2013 It should be understood that this iterative process does not necessarily converge on the true answer but will converge on an estimate with a finite truncation error, as will be demonstrated in the following example. As with the similar iterative methods, a termination criterion for convergence of the corrector is provided by 𝑗 |𝜀𝑎 | = | 𝑗−1 𝑗−1 𝑦𝑖+1 − 𝑦𝑖+1 𝑗 𝑦𝑖+1 | 𝑗 where 𝑦𝑖+1 and 𝑦𝑖+1 are the result from the prior and the present iteration of the corrector, respectively. تماما كما،دل غيرك على الخير تحب أن يدلك اآلخرون عليه أو بالبريد اإللكتروني9 4444 260 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy , eng-hs.neteng-hs.com شرح ومسائل محلولة مجانا بالموقعين [email protected] 9 4444 260 حمادة شعبان.م July 2013 EXAMPLE 25.5 Heun’s Method Problem Statement: Use Heun’s method to integrate y’ = 4e0.8x – 0.5y from x = 0 to x = 4 with a step size of 1. The initial condition at x = 0 is y = 2. Solution: Before solving the problem numerically, we can use calculus to determine the following analytical solution: 𝑦= 4 13 (𝑒 0.8𝑥 − 𝑒 −0.5𝑥 ) + 2𝑒 −0.5𝑥 This formula can be sued to generate the true solution values in the next table First, the slope at at (𝑥0 , 𝑦0 ) is calculated as 𝑦0′ = 4𝑒 0 − 0.5(2) = 3 This result is quite different from the actual average slope for the interval from 0 to 1.0, which is equal to 4.1946, as calculated from the differential equation. غالبا تكون الواجبات التي عليك أك ر من أبدأ بالواجبات،الحقوق التي تستحقها أو بالبريد اإللكتروني9 4444 260 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy , eng-hs.neteng-hs.com شرح ومسائل محلولة مجانا بالموقعين [email protected] 9 4444 260 حمادة شعبان.م July 2013 Continue: The numerical solution is obtained by using the predictor to obtain an estimate of y at 1.0: 𝑦10 = 2 + 3(1) = 5 Note that this is the result that would be obtained by the standard Euler method. The true value in the previous table shows that it corresponds to a percent relative error of 19.3 percent. Now, to improve the estimate for 𝑦𝑖+1 , we use the value 𝑦10 to predict the slope at the end of the interval 𝑦1′ = 𝑓(𝑥1 , 𝑦10 ) = 4𝑒 0.8(1) − 0.5(5) = 6.402164 Which can be combined with the initial slope to yield an average slope over the interval from x = 0 to 1 𝑦′ = 3+ 6.402164 2 = 4.701082 which is closer to the true average slope of 4.1946. This result can then be substituted into the corrector to give the prediction at x = 1 𝑦1 = 2 + 4.701082(1) = 6.701082 which represents a percent relative error of -8.18 percent. Thus, the Heun method without iteration of the corrector reduces the absolute value of the error by a factor of 2.4 as compared with Euler’s method. ماذا، اليوم يوافق تاريخ زواجنا:الزوجة . لنقف دقيقة حداد: الزوج،سنفعل أو بالبريد اإللكتروني9 4444 260 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy , eng-hs.neteng-hs.com شرح ومسائل محلولة مجانا بالموقعين [email protected] 9 4444 260 حمادة شعبان.م July 2013 Continue: Now this estimate can be used to refine or correct the prediction of 𝑦1 by substituting the new result back into the right-hand side of equation (25.16): 𝑦1 = 2 + [ 3+ 4𝑒 0.8(1) − 0.5(6.701082)] 2 1 = 6.275811 which represents an absolute percent relative error of 1.31 percent. This result, in turn, can be substituted back into equation (25.16) to further correct: 𝑦1 = 2 + [ 3+ 4𝑒 0.8(1) − 0.5(6.275811)] 2 1 = 6.382129 which represents an |𝜀𝑡 | of 3.03%. Notice how the errors sometimes grow as the iterations proceed. Such increases can occur, especially for large step sizes, and they prevent us from drawing the general conclusion that an additional iteration will always improve the result. However, for a sufficiently small step size, the iterations should eventually converge on a single value. For our case, 6.360865, which represents a relative error of 2.68 percent, is attained after 15 iterations. The previous table shows results for the remainder of the computation using the method with 1 and 15 iterations per step. الشخص الناجف هو في األساس شخص يستطيع أن يتخيل ويحول خياله إلى واقع أو بالبريد اإللكتروني9 4444 260 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy , eng-hs.neteng-hs.com شرح ومسائل محلولة مجانا بالموقعين [email protected] 9 4444 260 حمادة شعبان.م July 2013 In the previous example, the derivative is a function of both the dependent variable y and the independent variable x. For cases such as polynomials, where the ODE is solely a function of the independent variable, the predictor step is not required and the corrector is applied only once for each iteration. For such cases, the technique is expressed concisely as 𝑦𝑖+1 = 𝑦𝑖 + 𝑓(𝑥𝑖 )+ 𝑓(𝑥𝑖+1 ) 2 ℎ (25.18) Notice the similarity between the right-hand side of the previous equation and the trapezoidal rule. The connection between the two methods can be formally demonstrated by starting with the ordinary differential equation 𝑑𝑥 𝑑𝑦 = 𝑓(𝑥) This equation can be solved for y by integration: 𝑦𝑖+1 ∫𝑦 𝑖 𝑥 𝑑𝑦 = ∫𝑥 𝑖+1 𝑓(𝑥 )𝑑𝑥 𝑖 which yields 𝑥 𝑦𝑖+1 − 𝑦𝑖 = ∫𝑥 𝑖+1 𝑓(𝑥 )𝑑𝑥 𝑖 or 𝑥 𝑦𝑖+1 = 𝑦𝑖 + ∫𝑥 𝑖+1 𝑓(𝑥 )𝑑𝑥 𝑖 (25.21) طلبه بيكتبوا محاضرة مع الدكتور كل ما يمسف السبورة يقطعوا الورقة أو بالبريد اإللكتروني9 4444 260 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy , eng-hs.neteng-hs.com شرح ومسائل محلولة مجانا بالموقعين [email protected] 9 4444 260 حمادة شعبان.م July 2013 Now, recall that the trapezoidal rule is defined as 𝑥𝑖+1 ∫𝑥 𝑖 𝑓(𝑥 )𝑑𝑥 ≅ 𝑓(𝑥𝑖 )+ 𝑓(𝑥𝑖+1 ) 2 ℎ where h = 𝑥𝑖+1 − 𝑥𝑖 . Substituting equations yields 𝑦𝑖+1 = 𝑦𝑖 + 𝑓(𝑥𝑖 )+ 𝑓(𝑥𝑖+1 ) 2 ℎ which is equivalent to equation 25.18 Because the previous equation is a direct expression of the trapezoidal rule, the local truncation error is given by 𝐸𝑡 = − 𝑓 ′′ (𝜉) 12 ℎ3 where 𝜉 is between 𝑥𝑖 and 𝑥𝑖+1 . Thus, the method is second order because the second derivative of the ODE is zero when the true solution is quadratic. In addition, the local and global errors are 𝑂(ℎ3 ) and 𝑂(ℎ2 ), respectively. Therefore, decreasing the step size decreases the error at a faster rate than for Euler’s method. The next figure, which shows the result of using Heun’s method to solve the polynomial from example 25.1 demonstrates this behavior. ، لكااان ماااا تكلماااه،شاااخص تحباااه وإذا كلمته يقولوا عليك مجنون؟ أو بالبريد اإللكتروني9 4444 260 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy , eng-hs.neteng-hs.com شرح ومسائل محلولة مجانا بالموقعين [email protected] 9 4444 260 حمادة شعبان.م July 2013 25.2.2 The Midpoint (or Improved Polygon) Method The next figure illustrates another simple modification of Euler’s method. Called the mid-point method, this technique uses Euler’s method to predict a value of y at the midpoint of the interval (figure a): 𝑦𝑖+1/2 = 𝑦𝑖 + 𝑓 (𝑥𝑖 , 𝑦𝑖 ) ℎ 2 Then, this predicted value is used to calculate a slope at the midpoint: ′ 𝑦𝑖+1/2 = 𝑓(𝑥𝑖+1/2 , 𝑦𝑖+1/2 ) which is assumed to represent a valid approximation of the average slope for the entire interval. This slope is then used to extrapolate linearly from 𝑥𝑖 to 𝑥𝑖+1 (figure b): 𝑦𝑖+1 = 𝑦𝑖 + 𝑓(𝑥𝑖+1/2 , 𝑦𝑖+1/2 ) ℎ (25.27) حرف غير24 جملة مكونة من منقوط البد أن نكررها يوميا أك ر من عشر مرات؟ أو بالبريد اإللكتروني9 4444 260 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy , eng-hs.neteng-hs.com شرح ومسائل محلولة مجانا بالموقعين [email protected] 9 4444 260 حمادة شعبان.م July 2013 Observe that because 𝑦𝑖+1 is not on both sides, the corrector cannot be applied iteratively to improve the solution. This approach can also be linked to Newton-Cotes integration formulas. Recall that the simplest Newton-Cotes open integration formula, which is called the midpoint method, can be represented as 𝑏 ∫𝑎 𝑓(𝑥 )𝑑𝑥 = ≅ (𝑏 − 𝑎)𝑓(𝑥1 ) where 𝑥1 is the midpoint of the interval (a, b). Using the nomenclature for the present case, it can be expressed as 𝑥𝑖+1 ∫𝑥 𝑖 𝑓(𝑥 )𝑑𝑥 ≅ ℎ 𝑓(𝑥𝑖+1/2 ) ، األول رعد:أم أحمد عندها أبناء فماذا، مطر: ال الث، برق:ال اني تتوقع أن يكون اسم الرابع؟ أو بالبريد اإللكتروني9 4444 260 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy , eng-hs.neteng-hs.com شرح ومسائل محلولة مجانا بالموقعين [email protected] 9 4444 260 حمادة شعبان.م July 2013 Substitution of this formula into equation (25.21) yields the equation (25.27). Thus, just as the Heun method can be called the trapezoidal rule, the midpoint method gets its name from the underlying integration formula upon which it is based. The midpoint method is superior to Euler’s method because it utilizes a slope estimate at the midpoint of the prediction interval. 25.3 Runge-Kutta Methods Runge-Kutta (RK) methods achieve the accuracy of a Taylor series approach without requiring the calculation of higher derivatives. Many variations exist but all can be cast in the generalized form of 𝑦𝑖+𝜆 = 𝑦𝑖 + 𝜙(𝑥𝑖 , 𝑦𝑖 , ℎ)ℎ where 𝜙(𝑥𝑖 , 𝑦𝑖 , ℎ) is called an increment function, which can be interpreted as a representative slope over the interval. The increment function can be written in general form as 𝜙 = 𝑎1 𝑘1 + 𝑎2 𝑘2 + … + 𝑎𝑛 𝑘𝑛 شيء أنت تمكله ومع ذلك يستخدمه اآلخرون دون أن يستئذنوك؟ أو بالبريد اإللكتروني9 4444 260 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy , eng-hs.neteng-hs.com شرح ومسائل محلولة مجانا بالموقعين [email protected] 9 4444 260 حمادة شعبان.م July 2013 where the a’s are constants and the k’s are 𝑘1 = 𝑓(𝑥𝑖 , 𝑦𝑖 ) 𝑘2 = 𝑓(𝑥𝑖 + 𝑝1 ℎ, 𝑦𝑖 + 𝑞11 𝑘1 ℎ) 𝑘3 = 𝑓(𝑥𝑖 + 𝑝2 ℎ, 𝑦𝑖 + 𝑞21 𝑘1 ℎ +𝑞22 𝑘2 ℎ) . . . 𝑘𝑛 = 𝑓(𝑥𝑖 + 𝑝𝑛−1 ℎ, 𝑦𝑖 + 𝑞𝑛−1,1 𝑘1 ℎ +𝑞𝑛−1,2 𝑘2 ℎ + ⋯ +𝑞𝑛−1,𝑛−1 𝑘𝑛−1 ℎ ) where the p’s and q’s are constants. Notice that the k’s are recurrence relationships. That is, k1 appears in the equation for k2, which appears in the equation for k3, and so forth. Because each k is a functional evaluation, this recurrence makes RK methods efficient for computer calculations. Various types of Runge-Kutta methods can be devised by employing different numbers of terms in the increment function as specified by n. Note that the first-order RK method with n = 1 is, in fact, Euler’s method. Once n is chosen, values for the a’s, p’s and q’s are evaluated by setting equation (25.28) equal to terms in a Taylor series expansion. Thus, at least for the lower-order versions, the number of terms, n, usually represents the order of the approach. فهناك دائما،األمر ال ينتهي أبدا والهدف التالي،الغاية التالية أو بالبريد اإللكتروني9 4444 260 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy , eng-hs.neteng-hs.com شرح ومسائل محلولة مجانا بالموقعين [email protected] 9 4444 260 حمادة شعبان.م July 2013 For example, second-order RK methods use an increment function with two terms (n=2). These second-order methods will be exact if the solution to the differential equation is quadratic, the local truncation error is O(h 3) and the global error is O(h2). The third- and forth- order RK methods ( n=3 and 4, respectively) are developed. For these cases, the global truncation errors are O(h3) and O(h4) respectively. 25.3.1 Second-Order Runge-Kutta Methods The second-order version of equation (25.28) is 𝑦𝑖+1 = 𝑦𝑖 + 𝑓(𝑎1 𝑘1 + 𝑎2 𝑘2 )ℎ where 𝑘1 = 𝑓(𝑥𝑖 , 𝑦𝑖 ) 𝑘2 = 𝑓(𝑥𝑖 + 𝑝1 ℎ, 𝑦𝑖 + 𝑞11 𝑘1 ℎ) Values for a1, a2, p1, and q11 are evaluated by setting the previous equation equal to a Taylor series expansion to the second-order term. By doing this, we derive three equations to evaluate the four unknown constants. The three equations are 𝑎1 + 𝑎2 = 1 𝑎2 𝑝1 = 𝑎2 𝑞11 = 1 2 1 2 ،إذا لم يكن ما ستفعله صحيحا وإذا لم يكن ما،فال تفعله فال تقله،ستقوله صادقا أو بالبريد اإللكتروني9 4444 260 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy , eng-hs.neteng-hs.com شرح ومسائل محلولة مجانا بالموقعين [email protected] 9 4444 260 حمادة شعبان.م July 2013 Because we have three equations with four unknowns, we must assume a value of one of the unknowns to determine the other three. Suppose that we specify a value for a2. Then the previous three equations can be solved simultaneously for 𝑎1 = 1 − 𝑎2 𝑝1 = 𝑞11 = 1 2𝑎2 Because we can choose an infinite number of values for 𝑎2 , there are an infinite number of second-order RK methods. Every version would yield exactly the same results if the solution to the ODE were quadratic, linear or a constant. However, they yield different results when (as is typically the case) the solution is more complicated. We present three of the most commonly used and preferred versions: Heun Method with a Single Corrector (a2 = ½) Thus, a1 = ½ and p1 = q11 = 1. These parameters when substituted, yield 1 𝑦𝑖+1 = 𝑦𝑖 + ( 𝑘1 + 2 1 𝑘 )ℎ 2 2 where 𝑘1 = 𝑓(𝑥𝑖 , 𝑦𝑖 ) 𝑘2 = 𝑓(𝑥𝑖 + ℎ, 𝑦𝑖 + 𝑘1 ℎ) ،العقل يستطيع اإلجابة على األسئلة ولكن يجب على الخيال توجيهها أوال أو بالبريد اإللكتروني9 4444 260 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy , eng-hs.neteng-hs.com شرح ومسائل محلولة مجانا بالموقعين [email protected] 9 4444 260 حمادة شعبان.م July 2013 Note that 𝑘1 is the slope at the beginning of the interval and 𝑘2 is the slope at the end of the interval. Consequently, this second-order Runge-Kutta is actually Heun’s technique without iteration. The Midpoint Method (a2 = 1). Thus, a1 = 0, p1 = q11 = ½, and that gives 𝑦𝑖+1 = 𝑦𝑖 + 𝑘2 ℎ Where 𝑘1 = 𝑓(𝑥𝑖 , 𝑦𝑖 ) 1 1 2 2 𝑘2 = 𝑓 (𝑥𝑖 + ℎ, 𝑦𝑖 + 𝑘1 ℎ) This is the midpoint method. Ralston’s Method (a2 = 2/3) Choosing such value provides a minimal bound on the truncation error for the second-order RK algorithms. For this version, a1 = 1/3, and p1 = 3/2 and yields 1 𝑦𝑖+1 = 𝑦𝑖 + ( 𝑘1 + 3 2 𝑘 )ℎ 3 2 Where 𝑘1 = 𝑓(𝑥𝑖 , 𝑦𝑖 ) 3 3 4 4 𝑘2 = 𝑓 (𝑥𝑖 + ℎ, 𝑦𝑖 + 𝑘1 ℎ) عادة ما تتخفى الفرص في شكل عمل لذلك ال يتعرف عليها معظم الناس،شاق أو بالبريد اإللكتروني9 4444 260 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy , eng-hs.neteng-hs.com شرح ومسائل محلولة مجانا بالموقعين [email protected] 9 4444 260 حمادة شعبان.م July 2013 EXAMPLE 25.6 Comparison of Various Second-Order RK Schemes Problem Statement: Use the midpoint method and Ralston’s method to numerically integrate 𝑓(𝑥, 𝑦) = −2𝑥 3 + 12𝑥 2 − 20𝑥 + 8.5 from x = 0 to x = 4 using a step size of 0.5. The initial condition at x = 0 is y = 1. Compare the results with the values obtained using another second-order RK algorithm, that is, the Heun method without corrector iteration (next table). Solution: The first step in the midpoint method is to compute 𝑘1 = −2(0)3 + 12(0)2 − 20(0) + 8.5 = 8.5 However, because the ODE is a function of x only, this result has no bearing on the second step, and compute 𝑘2 = −2(0.25)3 + 12(0.25)2 − 20(0.25) + 8.5 = 4.21875 حتااى عناادما،إننااي ال أستساالم أباادا يقول لي الناس إنني لن أنجف أبدا أو بالبريد اإللكتروني9 4444 260 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy , eng-hs.neteng-hs.com شرح ومسائل محلولة مجانا بالموقعين [email protected] 9 4444 260 حمادة شعبان.م July 2013 Notice that this estimate of the slope is much closer to the average value for the interval (4.4375) than the slope at the beginning of the interval (8.5) that would have been used for Euler’s method. The slope at the midpoint can then be substituted to predict 𝑦(0.5) = 1 + 4.21875(0.5) = 3.109375 𝜀𝑡 = 3.4% The computation is repeated, and the results are summarized in the next figure and the previous table For Ralston’s method, k1 for the first interval also equals 8.5 and 𝑘2 = −2(0.375)3 + 12(0.375)2 − 20(0.375) + 8.5 = 2.58203125 The average slope is computed by 𝜙= 1 3 (8.5) + 2 3 (2.58203125) 𝑦(0.5) = 1 + 4.5546875(0.5) = 3.27734375 𝜀𝑡 = −1.82% The computation is repeated, and the results are summarized in the previous figure and table. هناك طريقة واحدة يمكنك الفشل وتلك هي االستسالم،بها أو بالبريد اإللكتروني9 4444 260 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy , eng-hs.neteng-hs.com شرح ومسائل محلولة مجانا بالموقعين [email protected] 9 4444 260 حمادة شعبان.م July 2013 Notice how all the second-order RK methods are superior to Euler’s method. 25.3.2 Third-Order Runge-Kutta Methods For n = 3, a derivation similar to the one for the second-order method can be performed. The result of this derivation is six equations with eight unknowns. Therefore, values for two of the unknowns must be specified a priori in order to determine the remaining parameters. One common version that results is 𝑦𝑖+1 = 𝑦𝑖 + 1 6 (𝑘1 + 4𝑘2 + 𝑘3 )ℎ where 𝑘1 = 𝑓(𝑥𝑖 , 𝑦𝑖 ) 1 1 2 2 𝑘2 = 𝑓 (𝑥𝑖 + ℎ, 𝑦𝑖 + 𝑘1 ℎ) 𝑘3 = 𝑓(𝑥𝑖 + ℎ, 𝑦𝑖 − 𝑘1 ℎ + 2𝑘2 ℎ) Note that if the derivative is a function of x only, this third-order method reduces to Simpson’s 1/3 rule. The third-order RK methods have local and global errors of O(h4) and O(h3), respectively, and yield exact results when the solution is cubic. When dealing with polynomials, the previous equations will be exact when the differential equation is cubic and the solution is quadratic. This is because Simpson’s 1/3 rule provides exact integral estimates for cubics. إن كل فكرة من أفكارك هي لبنة تضيفها إلى قصر أحالمك أو إلى قبر مشاريعك أو بالبريد اإللكتروني9 4444 260 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy , eng-hs.neteng-hs.com شرح ومسائل محلولة مجانا بالموقعين [email protected] 9 4444 260 حمادة شعبان.م July 2013 25.3.3 Fourth-Order Runge-Kutta Methods. The most popular RK methods are fourth order. As with the second-order approaches, there are an infinite number of versions. The following is the most commonly used form, and we therefore call it the classical fourth-order RK method: 𝑦𝑖+1 = 𝑦𝑖 + 1 6 (𝑘1 + 2𝑘2 + 2𝑘3 + 𝑘4 )ℎ where 𝑘1 = 𝑓(𝑥𝑖 , 𝑦𝑖 ) 1 1 2 2 1 1 2 2 𝑘2 = 𝑓 (𝑥𝑖 + ℎ, 𝑦𝑖 + 𝑘1 ℎ) 𝑘3 = 𝑓 (𝑥𝑖 + ℎ, 𝑦𝑖 + 𝑘2 ℎ) 𝑘3 = 𝑓(𝑥𝑖 + ℎ, 𝑦𝑖 + 𝑘3 ℎ) Notice that for ODEs that are a function of x alone, the classical fourth-order RK method is similar to Simpson’s 1/3 rule. In addition, the fourth-order RK method is similar to the Heun approach in that multiple estimates of the slope are developed in order to come up with an improved average slope for the interval. As shown in the next figure, each of the k’s represents a slope. ولكن ثمن,ثمن الكرامة والحرية فادح . السكوت عن الذل واالستعباد أفدح أو بالبريد اإللكتروني9 4444 260 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy , eng-hs.neteng-hs.com شرح ومسائل محلولة مجانا بالموقعين [email protected] 9 4444 260 حمادة شعبان.م July 2013 EXAMPLE 25.7 Classical Fourth-Order RK Method Problem Statement: (a) Use the classical fourth-order RK method to integrate 𝑓(𝑥, 𝑦) = −2𝑥 3 + 12𝑥 2 − 20𝑥 + 8.5 using a step size of = 0.5 and an initial condition of y = 1 at x = 0. (b) Similarly, integrate 𝑓(𝑥, 𝑦) = 4𝑒 0.8𝑥 − 0.5𝑦 using h = 0.5 with y(0) = 2 from x = 0 to 0.5 Solution: (a) Compute 𝑘1 = 8.5, 𝑘2 = 4.21875, 𝑘3 = 4.21875 and 𝑘4 = 1.25 𝑦(0.5) = 1 + { 1 6 [8.5 + 2(4.21875) + 2(4.21875) + 1.25] } 0.5 = 3.21875 which is exact. Thus, because the true solution is a quartic, the fourth-order method gives an exact result. ال تساااتطيع أن تطيااال حياتاااك ولكااان يمكن أن تجعلها أك ر عرضا وعمقا أو بالبريد اإللكتروني9 4444 260 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy , eng-hs.neteng-hs.com شرح ومسائل محلولة مجانا بالموقعين [email protected] 9 4444 260 حمادة شعبان.م July 2013 (b) The slope at the beginning of the interval is computed as 𝑘1 = 𝑓(0, 2) = 4𝑒 0.8(0) − 0.5(2) = 3 This value is used to compute a value of u and a slope at the midpoint, 𝑦(0.25) = 2 + 3(0.25) = 2.75 𝑘2 = 𝑓(0.25, 2.75) = 4𝑒 0.8(0.25) − 0.5(2.75) = 3.510611 This slope in turn is used to compute another value of y and another slope at the mid-point, 𝑦(0.25) = 2 + 3.510611 (0.25) = 2.877653 𝑘3 = 𝑓(0.25,2.877653) = 4𝑒 0.8(0.25) − 0.5(2.877653) = 3.44678 Next, this slope is used to compute a value of y and a slope at the end of the interval, 𝑦(0.5) = 2 + 3.071785(0.5) = 3.723392 𝑘4 = 𝑓(0.5, 3.723392) = 4𝑒 0.8(0.5) − 0.5(3.723392) = 4.105603 Finally, the four slope estimates are combined to yield an average slope. This average slope is then used to make the final prediction at the end of the interval. 𝜙= 1 6 [2 + 2(3.510611) + 2(3.446785) + 4.106603] = 3.503399 𝑦(0.5) = 2 + 3.503399(0.5) = 3.751699 which compares favorably with the true solution of 3.751521. أو بالبريد اإللكتروني9 4444 260 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy , eng-hs.neteng-hs.com شرح ومسائل محلولة مجانا بالموقعين [email protected] 9 4444 260 حمادة شعبان.م July 2013 Problem 25.7 Use the (a) Euler and (b) Heun (without iteration) methods to solve 𝑑2 𝑦 = 0.5 𝑡 + 𝑦 = 0 where y(0) = 2 and y’(0) = 0. Solve from x = 0 to 4 using h = 0.1. 𝑑𝑡 2 Solution The second-order ODE is transformed into a pair of first-order ODEs as in 𝑑𝑦 =𝑧 𝑦(0) = 2 𝑑𝑡 𝑑𝑧 𝑑𝑡 𝑧(0) = 0 = 0.5 𝑥 − 𝑦 (a) The first few steps of Euler’s method are x 0 0.1 0.2 0.3 0.4 0.5 y z 2 2 1.98 1.9405 1.8822 1.805995 0 -0.2 -0.395 -0.583 -0.76205 -0.93027 dy/dx 0 -0.2 -0.395 -0.583 -0.76205 -0.93027 dz/dx -2 -1.95 -1.88 -1.7905 -1.6822 -1.556 (b) For Heun (without iterating the corrector) the first few steps are x 0 0.1 0.2 0.3 0.4 0.5 y z dy/dx 2 1.99 1.96055 1.912446 1.846671 1.764385 0 -0.1975 -0.38801 -0.56963 -0.74052 -0.89899 0 -0.1975 -0.38801 -0.56963 -0.74052 -0.89899 dz/dx -2 -1.94 -1.86055 -1.76245 -1.64667 -1.51439 yend 2 1.97025 1.921749 1.855483 1.772619 1.674486 zend -0.2 -0.3915 -0.57407 -0.74587 -0.90519 -1.05043 dy/dx -0.2 -0.3915 -0.57407 -0.74587 -0.90519 -1.05043 dz/dx -1.95 -1.87025 -1.77175 -1.65548 -1.52262 -1.37449 ave slope -0.1 -0.2945 -0.48104 -0.65775 -0.82286 -0.97471 أو بالبريد اإللكتروني9 4444 260 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy , eng-hs.neteng-hs.com شرح ومسائل محلولة مجانا بالموقعين [email protected] 9 4444 260 حمادة شعبان.م July 2013 Problem 25.9 Solve from t = 0 to 3 with h = 0.1 using (a) Heun (without corrector) and (b) Ralston’s 2nd-order RK method: 𝑑𝑦 𝑑𝑡 = 𝑦 sin3 (𝑡) 𝑦(0) = 1 Solution (a) The Heun method without iteration can be implemented as in the following table: t 0 y 1 k1 0 yend 1 k2 0.000995 0.000498 0.1 1.00005 0.000995 1.000149 0.007843 0.004419 0.2 1.000492 0.007845 1.001276 0.025841 0.016843 0.3 1.002176 0.025865 1.004762 0.059335 0.0426 0.4 1.006436 0.059434 1.012379 0.11156 0.085497 0.5 1.014986 0.111847 1.02617 0.184731 0.148289 2.9 3.784421 0.051826 3.789604 0.01065 0.031238 3 3.787545 0.010644 3.78861 0.000272 0.005458 لو كان على الكالم ضرائب لتخلى ال رثارون عن ثالثة أرباع كالمهم أو بالبريد اإللكتروني9 4444 260 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy , eng-hs.neteng-hs.com شرح ومسائل محلولة مجانا بالموقعين [email protected] 9 4444 260 حمادة شعبان.م July 2013 Continue (b) The Ralston 2nd order RK method can be implemented as in the following table t 0 y 1 k1 0 yint 1 k2 0.000421 0.00028 0.1 1.000028 0.000995 1.000103 0.005278 0.003851 0.2 1.000413 0.007845 1.001001 0.020043 0.015977 0.3 1.002011 0.02586 0.049332 0.041508 1.00395 0.4 1.006162 0.059418 1.010618 0.096672 0.084254 0.5 1.014587 0.111803 1.022972 0.164537 0.146959 2.9 3.785066 0.051835 3.788954 0.017276 0.028796 3 0.001116 0.004293 3.787946 0.010646 3.788744 نعرف األمور الصحيحة وننادي لكن الصعب أن نلتزم بها،بها أو بالبريد اإللكتروني9 4444 260 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy , eng-hs.neteng-hs.com شرح ومسائل محلولة مجانا بالموقعين [email protected] 9 4444 260 حمادة شعبان.م July 2013 Problem 25.10 Solve the following problem numerically from t = 0 to 3: 𝑑𝑦 𝑑𝑡 = −𝑦 + 𝑡 2 𝑦(0) = 1 Use the third-order RK method with a step size of 0.5 Solution The solution results are as in the following table: t 0 y 1 k1 -1 k2 -0.6875 k3 -0.5625 -0.71875 0.5 0.640625 -0.39063 0.019531 0.144531 -0.02799 1 0.626628 0.373372 0.842529 0.967529 0.78517 1.5 1.019213 1.230787 1.735591 1.860591 1.67229 2 1.855358 2.144642 2.670982 2.795982 2.604092 2.5 3.157404 3.092596 3.631947 3.756947 3.562889 3 4.061152 4.608364 4.733364 4.537995 4.938848 العبيد أذالء:معظم الناس أذالء والسادة أذالء ألهوائهم،لسادتهم أو بالبريد اإللكتروني9 4444 260 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy , eng-hs.neteng-hs.com شرح ومسائل محلولة مجانا بالموقعين [email protected] 9 4444 260 حمادة شعبان.م
© Copyright 2026 Paperzz