I have this code for Runge Kutta method and keep showing error "index must be a positive interger " please I need help
Show older comments
%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;
end
y(i+1)
x(i+1)
Accepted Answer
More Answers (0)
Categories
Find more on General Physics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!