Runge Kutta 3 ODE
Show older comments
Part of bigger project. The task:
4. Implement the Runge-Kutta-3 (RK3) solver in Matlab and use it to compute the time evolution of the positions of the three bodies. For an ODE in general form y 0 = f(t, y) the RK3 method is defined as follows:
K1 = hf(ti , yi)
K2 = hf(ti + 1 2 h, yi + 1 2K1)
K3 = hf(ti + h, yi − K1 + 2K2)
yi+1 = yi + 1 6 (K1 + 4K2 + K3) where ti = t0 + ih.
As the name suggests, it is of third order accuracy.
Our code so far:
for i=1:n
t(i)=t(0)+i*h;
K1=h*f(t(i),y(i));
K2=h*f(t(i)+h/2,y(i)+K1/2);
K3=h*f(t(i)+h,y(i)-K1+2*K2);
y(i+1)=y(i)+(K1+4*K2+K3)/6;
end
We have tried putting n=different numbers but dont know what we are doing.
Error message:
Array indices must be positive integers or logical values.
Error in RK3 (line 7)
t(i)=t(0)+i*h;
What is the problem and how do solve the error?
Accepted Answer
More Answers (0)
Categories
Find more on Runge Kutta Methods 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!