Mercurial > repos > public > sbplib
comparison +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 |
comparison
equal
deleted
inserted
replaced
887:50d5a3843099 | 888:8732d6bd9890 |
---|---|
1 % Takes one time step of size dt using the rungekutta method | |
2 % starting from @arg v 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 |