Mercurial > repos > public > sbplib
changeset 930:34d882bffae4 feature/timesteppers
Add stepping function for RK with discrete data.
author | Martin Almquist <malmquist@stanford.edu> |
---|---|
date | Mon, 03 Dec 2018 16:26:18 -0800 |
parents | 0344fff87139 |
children | 384ca2331a12 |
files | +time/+rk/rungekuttaDiscreteData.m |
diffstat | 1 files changed, 30 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/+time/+rk/rungekuttaDiscreteData.m Mon Dec 03 16:26:18 2018 -0800 @@ -0,0 +1,30 @@ +% Takes one time step of size dt using the rungekutta method +% starting from @arg v. +% +% discreteData contains (a part of) the forcing function, already +% evaluated on the space-time grid. +% +% ODE: dv/dt = F(v,t) + discreteData(:, nt), where nt denotes the current time-point. +% +% coeffs is a struct holding the RK coefficients +% for the specific method. +% Also returns the stage approximations (V) and stage rates (K). +function [v, V, K] = rungekuttaDiscreteData(v, t , dt, F, coeffs, discreteData, n) + % Compute the intermediate stages k + 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); + end + V(:,i) = u; + K(:,i) = F(u,t+coeffs.c(i)*dt); + K(:,i) = K(:,i) + discreteData(:, n*coeffs.s + i); + 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