SHARE
TWEET

Scilab, tp6 rk4 function

SilLAwNeD Dec 3rd, 2018 118 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top