Presentation is loading. Please wait.

Presentation is loading. Please wait.

Solving the differential equation by Using the Runge-Kutta's

Similar presentations


Presentation on theme: "Solving the differential equation by Using the Runge-Kutta's"— Presentation transcript:

1 Solving the differential equation by Using the Runge-Kutta's
Method of order 4 Soongsin Joo 안녕하십니까? 저는 빛의 간섭과 회절 실험발표를 맡은 06학번 주숭신입니다.

2 Runge-Kutta's Method of order 4

3 Runge-Kutta's Method of order 4
dx/dt=f(x,t)라는 미분방정식이 t=t0 일때의 x값이 x0인 initial value를 갖을 때, 4차 Runge-Kutta’s Method로 상태변수 x(t)를 구하는 것이 문제이다. Step Size 를 h라고 했을때,

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

5 Runge-Kutta's Method of order 4 Source
/* Runge-Kutta's method of order 2 to solve a first-order differential equation */ /* Solve the system of single harmonic oscillator */ /* Include header files */ #include <stdio.h> #include <math.h> #include <conio.h> #include <stdlib.h> /* Define constant*/ #define w 2 #define h 0.01 /* Define global variables */ float t,x,v,SN,PT; char FOUTN[20]; FILE *FOUT; /* approximate solution state variable */ void RK4(); if((FOUT=fopen(FOUTN,"w"))==NULL){ printf("FILE OPEN ERROR...\n"); getch(); exit(-1); } printf("INPUT THE NUMBER OF STEPS PER ONE SECOND\n"); scanf("%f",&SN); printf("INPUT PLOTTING TIME\n"); scanf("%f",&PN); m=100; k=400; w=sqrt(k/m); h=1/SN; t=0; x0=10; v0=0; x=x0;v=v0; for(i=0;i<=SN*PN;i++){ printf("%10.3E\t%10.3E\t%10.3E\n",t,x,v); fprintf(FOUT,"%10.3E\t %10.3E\t%10.3E\n",t,x,v); RKM4(); fclose(FOUT);

6 Runge-Kutta's Method of order 4 Source
void RK4(){ float ti,xi,vi,f1,f2,f3,f4,g1,g2,g3,g4; /* Define local variable */ ti=t; xi=x; vi=v; f1=F(v); g1=G(x); x=xi+h*f1/2; v=vi+h*g1/2; t=ti+h/2; f2=F(v); g2=G(x); x=xi+h*f2/2; v=vi+h*g2/2; f3=F(v); g3=G(x); t=ti+h; x=xi+h*f3; v=vi+h*g3; f4=F(v); g4=G(x); x=xi+h*(f1+2*f2+2*f3+f4)/6; v=vi+h*(g1+2*g2+2*g3+g4)/6; } /* dx/dt=F(x(t),v(t),t)=v */ float F(float V){ float f; f=V; return f; } /* dv/dt=G(x(t),v(t),t)=-w*w*x */ float G(float X){ float g; g=-w*w*X; return g;

7


Download ppt "Solving the differential equation by Using the Runge-Kutta's"

Similar presentations


Ads by Google