diff +time/+expint/Magnus_4.m @ 510:71908bbce2e1 feature/quantumTriangles

tried to add 4th order magnus integrator which does not work
author Ylva Rydin <ylva.rydin@telia.com>
date Fri, 02 Jun 2017 17:46:01 +0200
parents
children 4ef2d2a493f1
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/+time/+expint/Magnus_4.m	Fri Jun 02 17:46:01 2017 +0200
@@ -0,0 +1,20 @@
+% Takes one time step of size k using a fourth order magnus integrator
+% starting from v_0 and where the function F(v,t) gives the
+% time derivatives.
+function v = Magnus_4(v,D, t , k)
+
+if isa(D,'function_handle')
+   % v = krylov(k*D(t +k/2*t),v);
+   c1 = 1/2 - sqrt(3)/6;
+   c2 = 1/2 + sqrt(3)/6;  
+   
+   A1 = D(t +c1*k);
+   A2 = D(t + c2*k);
+   Omega = k/2*(A1 + A2) + sqrt(3)*k^2/12*(A1*A2-A2*A1);
+   v = expm(Omega)*v;
+else
+   %v = krylov(k*D,v);
+   v = expm(k*D)*v;
+end
+
+end
\ No newline at end of file