Solve The 1 st Order Differential Equations Using

  • Slides: 4
Download presentation
Solve The 1 st Order Differential Equations Using The 2 nd Order Runge. Kutta.

Solve The 1 st Order Differential Equations Using The 2 nd Order Runge. Kutta. Sung-Ju Kang Department of Physics Kangwon National University Runge-Kutta methods have the high-order local truncation error while elimination the need to compute and evaluate the derivatives of . Runge-Kutta methods of order two 1

Algorism INPUT function f(t) ; begin point a ; OUTPUT application y to t

Algorism INPUT function f(t) ; begin point a ; OUTPUT application y to t at the ( N + 1 ) values of t. Step 1 : Set a initial conditions t 0 , y 0 , integer N ; initial condition f(t) = y ; , N. Step 2 : For i = 1, 2, … N do Step 3, Step 4, Step 5 Step 3 : K 1 = K 2 = * f 1(y 1, t 0) * f 1(y 1+K 1/2 , t 0+ /2) , Step 4 : y = y 0 + K 2. Step 5 : t = t 0+ i * . Step 6 : Print ( y , t ). Step 6 : STOP. 2

Programming with C language /*2 nd Order Runge-Kutta method to solve a differential equation

Programming with C language /*2 nd Order Runge-Kutta method to solve a differential equation */ #include <stdio. h> #include <math. h> #include <conio. h> #include <stdlib. h> long double y, t, dt, N, f ; /* A routine for integration of a differential equation */ void RUNGE 2() { int i; long double t 0, y 0, f 1, f 2; for(i=0; i<=N; ++i) { /* General Routine */ void RUNGE 2(); t 0=t; y 0=y; /* Routine dependent on the system */ void F(); y=y 0+dt*f 1/2; /* The system */ /* dy/dt=F(y, t)=-y+t+1 */ void main() { t = 0 ; y = 0. 5 ; dt = 0. 2; N = 10 ; t=t 0+dt/2; F(); f 1=f; F(); f 2=f; y=y 0+dt*f 2; t=t+dt/2; printf("t=%18. 13 Lf x=%18. 13 Lf₩n", t, y); } RUNGE 2(); getch(); } } { /* A routine to return the value of F(y, t) */ void F() f=-y+t+1; } 3

Summary 1. Runge-Kutta methods have the high-order local truncation error while elimination the need

Summary 1. Runge-Kutta methods have the high-order local truncation error while elimination the need to compute and evaluate the derivatives of . 2. In the second-order methods, the local truncation error is 0(h 2), and the cost is two functional evaluation per step. 4