Monday, 7 November 2011

Runge-Kutta Method

%% Write a MATLAB program to find y for x =0.2 given that dy/dx =

%% x+y and y=1 when x=0 using Runga-Kutta fourth order method.



% Given

x0 = 0;

y0 = 1;

%let

h = 0.2;

fxy = x0+y0;

k1 =h*fxy;

x0=x0+h/2;y0=y0+k1/2;

fxy = x0+y0;

k2=h*fxy;

y0=y0-k1/2+k2/2;

fxy = x0+y0;

k3=h*fxy;

x0=x0+h/2;y0=y0-k2/2+k3;

fxy = x0+y0;

k4=h*fxy;

k=(k1+2*k2+2*k3+k4)/6

%then y = y0+k

fprintf (' Approximate value of y for x = %2.3f is = %2.4f \n',x0,1+k);

No comments:

Post a Comment