diff options
author | Vasil Zlatanov <v@skozl.com> | 2017-02-23 12:56:18 +0000 |
---|---|---|
committer | Vasil Zlatanov <v@skozl.com> | 2017-02-23 12:56:18 +0000 |
commit | 3cf86838be8a410e3bf70d450d50db3d799026e9 (patch) | |
tree | 66707e6fbbadd72cb60aafa63e22e2a233374a89 /coursework17/RK4second.m | |
parent | 0cf1fa44a5e8d35ce263954bd53bb94b7b0f9099 (diff) | |
download | e2-matlab-3cf86838be8a410e3bf70d450d50db3d799026e9.tar.gz e2-matlab-3cf86838be8a410e3bf70d450d50db3d799026e9.tar.bz2 e2-matlab-3cf86838be8a410e3bf70d450d50db3d799026e9.zip |
accept exerercise 3 form Alex
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
|