Advertisement
Guest User

Untitled

a guest
May 19th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.29 KB | None | 0 0
  1. % Runge-Kutta av orden 4.
  2. function x = rk4(T,N)
  3.     f = @(t,x) 2*x/(t+1)-x^2/(t+1)^3;
  4.     h = T/N;
  5.     x = 1;
  6.     for n = 0:N-1
  7.             k1 = h*f(n*h, x);
  8.             k2 = h*f(n*h+ h/2, x+k1/2);
  9.             k3 = h*f(n*h+ h/2, x+k2/2);
  10.             k4 = h*f(n*h+ h, x+k3);
  11.         x= x+1/6*(k1+2*k2+2*k3+k4);
  12.     end
  13. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement