%Script that demonstrates the Runge-Kutta integration for a first order problem %the problem to be solved is: %f(xi,yi)=(1/2)-xi+2*yi h=0.2; %h is the time step. y0=1; yi=y0; xf=0.2; x0=0; xi=x0; n=xf-x0/xf; %iterate for i=0:n f(xi,yi)=(1/2)-xi+2*yi; k1=f(xi,yi)*h; k2=f(xi+(h/2),yi+h/2*k1); k3=f(xi+h/2,yi+(h/2)*k2); k4=f(xi+h,yi+h*k3); y(i+1)=yi+(1/6)*(k1+2*k2+2*k3+k4); x(i+1)=xi+h;
endy(i+1)x(i+1)
Best Answer