Presentation is loading. Please wait.

Presentation is loading. Please wait.

TNPL JoongJin-Cho Runge-kutta’s method of order 4.

Similar presentations


Presentation on theme: "TNPL JoongJin-Cho Runge-kutta’s method of order 4."— Presentation transcript:

1 TNPL JoongJin-Cho Runge-kutta’s method of order 4

2 TNPL JoongJin-Cho This routine solve the initial value problem at equidistant points Here the function f(x,t) is continuous the at equidistant points Here the function f(x,t) is continuous theinterval Algorithm

3 TNPL JoongJin-Cho Algorithm

4 TNPL JoongJin-Cho Runge-Kutta ’ s method of order 4 to solve a first-order differential equation Algorithm

5 TNPL JoongJin-Cho public static void main(String args[]){ int i; double t,ti,h,x,xi, N=5; double f; //Differential equation dx/dt=f(x,t)=x+t double t0,x0,f1,f2,f3,f4; x=xi; t=ti; f=x+t; for(i=0;i<N;i++){ t0=t;x0=x; f=x+t; // K1 f1=f; x=x0+h*f1/2; t=t0+h/2; f=x+t; // K2 f2=f; x=x0+h*f2/2; t=t0+h/2; f=x+t; // K3 f3=f; x=x0+h*f3; t=t0+h; f=x+t; // K4 f4=f; x=x0+h*(f1+2*f2+2*f3+f4)/6; // Xi+1 t=t0+h; // ti+1 Java Programming //4th order Runge-Kutta method, need derivative f

6 TNPL JoongJin-Cho import java.io.*; public class RungeKutta2{ static BufferedReader bf = new BufferedReader (new InputStreamReader(System.in)); //4th order Runge-Kutta method, need derivative f public static void main(String args[])throws IOException { int i; double t,ti,h,x,xi,N=5; double f; double t0,x0,f1,f2,f3,f4; String str; System.out.print("Input initial value ti = >"); str=bf.readLine(); ti=Double.parseDouble(str); System.out.print("Input initial value xi = >"); str=bf.readLine(); xi=Double.parseDouble(str); System.out.print("step size h = >"); str=bf.readLine(); h=Double.parseDouble(str);

7 TNPL JoongJin-Cho x=xi; t=ti; f=x+t; for(i=0;i<N;i++){ t0=t;x0=x; f=x+t; f1=f; x=x0+h*f1/2; t=t0+h/2; f=x+t; f2=f; x=x0+h*f2/2; t=t0+h/2; f=x+t; f3=f; x=x0+h*f3; t=t0+h; f=x+t; f4=f; x=x0+h*(f1+2*f2+2*f3+f4)/6; t=t0+h; System.out.println ("t="+(float)t+"\t"+"x="+x+"\t"+"f="+f); }


Download ppt "TNPL JoongJin-Cho Runge-kutta’s method of order 4."

Similar presentations


Ads by Google