Mercurial > repos > public > sbplib
comparison +time/+rk/rungekuttaDiscreteData.m @ 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 | |
children |
comparison
equal
deleted
inserted
replaced
929:0344fff87139 | 930:34d882bffae4 |
---|---|
1 % Takes one time step of size dt using the rungekutta method | |
2 % starting from @arg v. | |
3 % | |
4 % discreteData contains (a part of) the forcing function, already | |
5 % evaluated on the space-time grid. | |
6 % | |
7 % ODE: dv/dt = F(v,t) + discreteData(:, nt), where nt denotes the current time-point. | |
8 % | |
9 % coeffs is a struct holding the RK coefficients | |
10 % for the specific method. | |
11 % Also returns the stage approximations (V) and stage rates (K). | |
12 function [v, V, K] = rungekuttaDiscreteData(v, t , dt, F, coeffs, discreteData, n) | |
13 % Compute the intermediate stages k | |
14 K = zeros(length(v), coeffs.s); | |
15 V = zeros(length(v), coeffs.s); | |
16 for i = 1:coeffs.s | |
17 u = v; | |
18 for j = 1:i-1 | |
19 u = u + dt*coeffs.a(i,j)*K(:,j); | |
20 end | |
21 V(:,i) = u; | |
22 K(:,i) = F(u,t+coeffs.c(i)*dt); | |
23 K(:,i) = K(:,i) + discreteData(:, n*coeffs.s + i); | |
24 end | |
25 % Compute the updated solution as a linear combination | |
26 % of the intermediate stages. | |
27 for i = 1:coeffs.s | |
28 v = v + dt*coeffs.b(i)*k(:,i); | |
29 end | |
30 end |