annotate +time/+rk/rungekutta.m @ 1223:9fddc8749445 rv_diffOp_test

Closing branch
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Mon, 05 Aug 2019 10:48:37 +0200
parents c6fcee3fcf1b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
846
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
1 % Takes one time step of size dt using the rungekutta method
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
2 % starting from v_0 and where the function F(v,t) gives the
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
3 % time derivatives. coeffs is a struct holding the RK coefficients
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
4 % for the specific method.
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
5 function v = rungekutta(v, t , dt, F, coeffs)
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
6 % Compute the intermediate stages k
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
7 k = zeros(length(v), coeffs.s);
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
8 for i = 1:coeffs.s
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
9 u = v;
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
10 for j = 1:i-1
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
11 u = u + dt*coeffs.a(i,j)*k(:,j);
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
12 end
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
13 k(:,i) = F(u,t+coeffs.c(i)*dt);
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
14 end
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
15 % Compute the updated solution as a linear combination
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
16 % of the intermediate stages.
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
17 for i = 1:coeffs.s
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
18 v = v + dt*coeffs.b(i)*k(:,i);
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
19 end
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
20 end