changeset 917:878652b22157 feature/timesteppers

Make time.rk.rungekutta return stage approximations and stage rates in addition to the solution after one time step.
author Martin Almquist <malmquist@stanford.edu>
date Mon, 26 Nov 2018 16:12:27 -0800
parents d1c1615bd1a5
children 679f4ddd982f
files +time/+rk/rungekutta.m
diffstat 1 files changed, 7 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/+time/+rk/rungekutta.m	Mon Nov 26 16:08:54 2018 -0800
+++ b/+time/+rk/rungekutta.m	Mon Nov 26 16:12:27 2018 -0800
@@ -2,15 +2,18 @@
 % 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)
+% Also returns the stage approximations (V) and stage rates (K).
+function [v, V, K] = rungekutta(v, t , dt, F, coeffs)
     % Compute the intermediate stages k
-    k = zeros(length(v), coeffs.s);
+    K = zeros(length(v), coeffs.s);
+    V = 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);
+            u = u + dt*coeffs.a(i,j)*K(:,j);
         end
-        k(:,i) = F(u,t+coeffs.c(i)*dt);
+        V(:,i) = u;
+        K(:,i) = F(u,t+coeffs.c(i)*dt);
     end
     % Compute the updated solution as a linear combination
     % of the intermediate stages.