Runge Kutta 3 ODE
    18 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
    Hugo B
 le 4 Fév 2022
  
    
    
    
    
    Réponse apportée : Alan Stevens
      
      
 le 4 Fév 2022
            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?
0 commentaires
Réponse acceptée
  Alan Stevens
      
      
 le 4 Fév 2022
        You can't have
t(i)=t(0)+i*h;
indices must be a positive integer - you have t(0), Matlab doesn't like this!
0 commentaires
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

