diff +time/+rk/rungekutta.m @ 888:8732d6bd9890 feature/timesteppers

Add general Runge-Kutta class - Add a general Runge-Kutta class which time integrates the solution based on coefficients obtained from a Butcher tableau - Add butcher tableau which returns coefficents for the specified Runge-Kutta method - Remove RungKutta4proper, since obsolete
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Thu, 15 Nov 2018 17:10:01 -0800
parents
children 878652b22157
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/+time/+rk/rungekutta.m	Thu Nov 15 17:10:01 2018 -0800
@@ -0,0 +1,20 @@
+% Takes one time step of size dt using the rungekutta method
+% starting from @arg v and where the function F(v,t) gives the
+% time derivatives. coeffs is a struct holding the RK coefficients
+% for the specific method.
+function v = rungekutta(v, t , dt, F, coeffs)
+    % Compute the intermediate stages k
+    k = zeros(length(v), coeffs.s);
+    for i = 1:coeffs.s
+        u = v;
+        for j = 1:i-1
+            u = u + dt*coeffs.a(i,j)*k(:,j);
+        end
+        k(:,i) = F(u,t+coeffs.c(i)*dt);
+    end
+    % Compute the updated solution as a linear combination
+    % of the intermediate stages.
+    for i = 1:coeffs.s
+        v = v + dt*coeffs.b(i)*k(:,i);
+    end
+end
\ No newline at end of file