diff options
Diffstat (limited to 'coursework17/RK4second.m')
-rw-r--r-- | coursework17/RK4second.m | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/coursework17/RK4second.m b/coursework17/RK4second.m new file mode 100644 index 0000000..7388c27 --- /dev/null +++ b/coursework17/RK4second.m @@ -0,0 +1,12 @@ +function [x, y] = RK4second(t,x,y,h,g,f)
+k1x = h*g(t, x,y);
+k1y = h*f(t, x,y);
+k2x = h*g(t+h/3, x+k1x/3, y+k1y/3);%if it doesnt work try k1y after y
+k2y = h*f(t+h/3, x+k1x/3, y+k1y/3);
+k3x = h*g(t+2*h/3, x-k1x/3+k2x, y-k1y/3+k2y);
+k3y = h*f(t+2*h/3, x-k1x/3+k2x, y-k1y/3+k2y);
+k4x = h*g(t+h, x+k1x-k2x+k3x, y+k1y-k2y+k3y);
+k4y = h*f(t+h, x+k1x-k2x+k3x, y+k1y-k2y+k3y);
+x = x+(1/8)*(k1x+3*k2x+3*k3x+k4x);
+y = y+(1/8)*(k1y+3*k2y+3*k3y+k4y);
+end
|