Advertisement
SilLAwNeD

Scilab, tp6 rk4 function

Dec 3rd, 2018
2,446
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 0.44 KB | None | 0 0
  1. function [X] = rk4(a, t0, T, N, f)
  2.     p = size (a, 1);
  3.     X = zeros (p, N);
  4.    
  5.     t = t0;
  6.     X(:, 1) = a;
  7.     h = T / N;
  8.     k = h/6;
  9.     l = h/2;
  10.    
  11.     for i=1:N-1
  12.         K0 = f(t, X(:, i));
  13.         K1 = f(t + l, X(:, i) + l * K0);
  14.         K2 = f(t + l, X(:, i) + l * K1);
  15.         K3 = f(t + h, X(:, i) + h * K2);
  16.         X(:, i+1) = X(:, i) + k * ( K0 + 2 * K1 + 2 * K2 + K3 )
  17.         t = t + h;
  18.     end
  19.    
  20. endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement