Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. function[t, y] = runge_kutta(f, T, PP)
  2.  
  3. h = 0.001;
  4. t = T(1):h:T(2);
  5.  
  6. y(1,1) = PP(1);
  7. y(2,1) = PP(2);
  8.  
  9. for idx = 1 : length(t)-1
  10.  
  11. k_1 = h * f(t(idx), y(:, idx));
  12. k_2 = h * f(t(idx) + h/2, y(:, idx) + k_1'./2);
  13. k_3 = h * f(t(idx) + h/2, y(:, idx) + k_2'./2);
  14. k_4 = h * f(t(idx) + h, y(:, idx) + k_3');
  15.  
  16. y(:, idx + 1) = y(:, idx) + 1/6. * (k_1 + 2. * k_2 + 2. * k_3 + k_4);
  17. end
  18. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement