Advertisement
ruhan008

Runge Kutta

Nov 1st, 2024
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.40 KB | None | 0 0
  1. function rk = RK_method(x0, y0, h, x)
  2.     f = @(x, y) (-2 * x ^ 3) + (12 * x ^ 2) - (20 * x) + 8.5;
  3.     n = (x - x0) / h;
  4.     for i = 1 : n
  5.         k1 = h * f(x0, y0);
  6.         k2 = h * f(x0 + h / 2, y0 + k1 / 2);
  7.         k3 = h * f(x0 + h / 2, y0 + k2 / 2);
  8.         k4 = h * f(x0 + h, y0 + k3);
  9.  
  10.         y0 = y0 + (k1 + 2 * k2 + 2 * k3 + k4) / 6;
  11.         x0 = x0 + h;
  12.     end
  13.  
  14.     rk = y0;
  15. end
  16.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement