From 3cf86838be8a410e3bf70d450d50db3d799026e9 Mon Sep 17 00:00:00 2001 From: Vasil Zlatanov Date: Thu, 23 Feb 2017 12:56:18 +0000 Subject: accept exerercise 3 form Alex --- coursework17/RK4second.m | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 coursework17/RK4second.m (limited to 'coursework17/RK4second.m') 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 -- cgit v1.2.3-54-g00ecf