Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
PART 7 Ordinary Differential Equations ODEs Ordinary Differential Equations Part 7 • Equations which are composed of an unknown function and its derivatives are called differential equations. dv c g v dt m v - dependent variable t - independent variable • Differential equations play a fundamental role in engineering because many physical phenomena are best formulated mathematically in terms of their rate of change. Ordinary Differential Equations • When a function involves one dependent variable, the equation is called an ordinary differential equation (ODE). •A partial differential equation (PDE) involves two or more independent variables. Ordinary Differential Equations Differential equations are also classified as to their order: 1. A first order equation includes a first derivative as its highest derivative. - Linear 1st order ODE dy y f (x ) dx dy - Non-Linear order ODE f ( x, y ) dx Where f(x,y) is nonlinear 1st Ordinary Differential Equations 2. A second order equation includes a second derivative. 2 d y dy nd p Qy f (x ) - Linear 2 order ODE 2 dx dx - Non-Linear 2nd order ODE 2 d y dy p ( x, y ) Q ( x, y ) y f ( x ) 2 dx dx • Higher order equations can be reduced to a system of first order equations, by redefining a variable. Ordinary Differential Equations Runge-Kutta Methods This chapter is devoted to solving ODE of the form: dy f ( x, y ) dx • Euler’s Method dy dy f ( x, y ) dx f ( x, y ) dx solution : Solution Solution : yi 1 yi f ( xi , yi ) h yi 1 yi f ( xi , yi ) h Runge-Kutta Methods dy f ( x, y ) dx Solution : dy yi 1 yi f (fx(,xyi ,)yi ) h dx Solution : yi 1 yi f ( xi , yi ) h Euler’s Method: Example Obtain a solution between x = 0 to x = 4 with a step size of 0.5 for: dy 3 dx 2 x 12 x 2 20 x 8.5 Initial conditions are: x = 0 to y = 1 ulerSolution: Solution : yi 1 yi f ( xi , yi ) h y (0.5) y (0 ) f (0,1).(0.5) 1.0 8.5 x0.5 5.25 y (1.0 ) y (0.5) f (0.5,5.25).(0.5) 5.25 ( 2(0.5)3 12(0.5) 2 20(0.5) 8.5).(0.5) 5.875 y ( 2.0 ) y (1.0 ) f (1.0,5.875).(0.5) 5.25 ( 2(1.0 )3 12(1.0 ) 2 20(1.0 ) 8.5).(0.5) 5.125 Euler’s Method: Example • Although the computation captures the general trend solution, the error is considerable. • This error can be reduced by using a smaller step size. 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. • Simple modifications are available: – Heun’s Method – The Midpoint Method – Ralston’s Method Runge-Kutta Methods • Runge-Kutta methods achieve the accuracy of a Taylor series approach without requiring the calculation of higher derivatives. y i 1 y i (x i , y i , h )h a1k 1 a2 k 2 an k n a ' s constants k 1 f (x i , y i ) Increment function (representative slope over the interval) k 2 f (x i p1h , y i q11k 1h ) k 3 f (x i p 3 h , y i q 21k 1h q 22 k 2 h ) k n f (x i p n 1h , y i q n 1k 1h q n 1,2 k 2 h p ' s and q ' s are constants q n 1,n 1k n 1h ) Runge-Kutta Methods • Various types of RK methods can be devised by employing different number of terms in the increment function as specified by n. 1. First order RK method with n=1 is Euler’s method. – Error is proportional to O(h) 2. Second order RK methods: - Error is proportional to O(h2) yi 1 yi (a1k1 a2 k 2 )h k1 f ( x i , yi ) k 2 f ( xi p1h, yi q11k1h) • Values of a1, a2, p1, and q11 are evaluated by setting the second order equation to Taylor series expansion to the second order term. Runge-Kutta Methods • Three equations to evaluate the four unknown constants are derived: a1 a2 1 1 a 2 p1 2 1 a2 q11 2 A value is assumed for one of the unknowns to solve for the other three. Runge-Kutta Methods 1 1 a1 a2 1, a 2 p1 , a2 q11 2 2 • We can choose an infinite number of values for a2,there are an infinite number of second-order RK methods. • Every version would yield exactly the same results if the solution to ODE were quadratic, linear, or a constant. • However, they yield different results if the solution is more complicated (typically the case). f ( x, y ) dxSolution : Runge-KuttaSolution Methods : 1 2 yi 1 yi ( k1 k 2 ) h Three 1 3are: 1 3 dy of the most commonly used methods f ( x, y ) y i 1 yi ( k1 k 2 ) h yi 1 yi (a1k1 a2 k 2 )h k1 f ( xi , 2yi ) 2 dx dy f ( x, y ) : , y ) with a SinglekCorrector • Huen Method (ai )2=1/2) kSolution f ( x dx 1 f ( xi , y 1 i i 3 3 k 2 : f ( xi h, yi k1h ) dy 1 1 Solution ky2i 1f y(fix(i x(, p yk1)h1 ,yi k2q)11 hk1hk) 2dy f ( xi h4), ( yi k14h ) 2 2 yi 1 yi k 2f(hx, y ) dx dx k1 f ( xi , yi ) k12 f ( xi , yi ) • The Midpoint = 1) Solution : Method (a Solution : k 2 f ( xi h ), ( yi k1h ) 1 1 dy yi 1 f ( yx,i y) k 2 h k 2 f ( xi h, yi 1 k1h2) yi 1 2yi ( k21 k 2 ) h dx 3 3 k1 f ( xi , yi ) Solution : Method (a2= 2/3) k1 f ( xi , yi ) • Raltson’s 1 2 1 1 3 3 yki 21 yfi (x(i k1 h, ky2i ) h k1hk)2 f ( xi h, yi k1h ) 2 3 2 3 4 4 Runge-Kutta Methods y • Heun’s Method: Involves the determination dydy of two derivatives for the f ( x , y ) interval , y )initial point dxdx fat( xthe and the end point. f(xi,yi) xi Solution Solution :: 11 1 1 yiyi11 yyii (( k1k1 k2 )k 2h) h 22 2 2 k f ( x , y ) 1 i i k f (x , y ) i x xi+h y ea k 2 f ( xi h ), ( yi k1h ) 1 f(xi+h,yi+k1h) i Slope: 0.5(k1+k2) k 2 f ( xi h ), ( yi k1h ) xi x xi+h Runge-Kutta Methods y • Midpoint Method: Uses dy Euler’s method to predict off (yxat , ythe ) midpoint of ady value dx f ( x, y ) the dxinterval: Solution : Solution yi 1 yi: k 2 h yki 1 fy(i x,ky2 ) h 1 i f(xi,yi) xi f(xi+h/2,yi+k1h/2) x xi+h/2 y i k1 f ( xi , yi )1 1 k 2 f ( xi 1 h, yi 1 k1h ) k 2 f ( xi 2h, yi 2k1h ) 2 2 Chapter 25 ea Slope: k2 xi x xi+h dy Runge-Kutta Methods dy f ( x, y ) dx f ( x, y ) •dx Ralston’s Method: Solution : Solution : 1 2 yi 1 yi ( 1k1 2k 2 ) h yi 1 yi (3 k1 3 k 2 ) h 3 k1 f ( xi , yi )3 k1 f ( xi , y3i ) 3 k 2 f ( xi h, yi k1h ) 3 3 4 4 k f ( x h, y k h ) 2 i 4 i 4 y f(xi,yi) xi f(xi+ 3/4 h, yi+3/4k1h) xi+3/4h x y ea 1 Slope: (1/3k1+2/3k2) Chapter 25 xi xi+h x Chapter 25 22 Runge-Kutta Methods 3. Third order RK methods 1 yi 1 yi (k1 4k 2 k3 ) h 16 yi 1 yi (k1 4k 2 k3 )h 6 where k where f (x , y ) 1 i i k1 f ( x i , yi )1 1 k 2 f ( xi h, yi k1h) 12 1 2 k 2 f ( xi h, yi k1h) k3 f ( xi 2h, yi k21h 2k 2 h) k3 f ( xi h, yi k1h 2k 2 h) Chapter 25 Runge-Kutta Methods 4. Fourth order RK methods 1 yi 1 yi (k1 2k 2 2k3 k 4 )h 6 where k1 f ( x i , yi ) 1 1 k 2 f ( xi h, yi k1h) 2 2 1 1 k3 f ( xi h, yi k 2 h) 2 2 k3 f ( xi h, yi k3 h) Chapter 25 Comparison of Runge-Kutta Methods Use first to fourth order RK methods to solve the equation from x = 0 to x = 4 Initial condition y(0) = 2, exact answer of y(4) = 75.33896 f ( x, y) 4e 0.8 x 0.5 y Chapter 25