Mercurial > repos > public > sbplib
comparison +time/+rk/rungekutta.m @ 846:c6fcee3fcf1b feature/burgers1d
Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Thu, 20 Sep 2018 17:51:19 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
845:1e057b0f2fed | 846:c6fcee3fcf1b |
---|---|
1 % Takes one time step of size dt using the rungekutta method | |
2 % starting from v_0 and where the function F(v,t) gives the | |
3 % time derivatives. coeffs is a struct holding the RK coefficients | |
4 % for the specific method. | |
5 function v = rungekutta(v, t , dt, F, coeffs) | |
6 % Compute the intermediate stages k | |
7 k = zeros(length(v), coeffs.s); | |
8 for i = 1:coeffs.s | |
9 u = v; | |
10 for j = 1:i-1 | |
11 u = u + dt*coeffs.a(i,j)*k(:,j); | |
12 end | |
13 k(:,i) = F(u,t+coeffs.c(i)*dt); | |
14 end | |
15 % Compute the updated solution as a linear combination | |
16 % of the intermediate stages. | |
17 for i = 1:coeffs.s | |
18 v = v + dt*coeffs.b(i)*k(:,i); | |
19 end | |
20 end |