Hi everyone!
I am trying to compute Lie brackets of two vector fields let us say F0 and F1.
They’re in dimension 6 and I need brackets until length 5 (thus, derivative up to order 5). Unfortunately this is extremely slow to compute at one point, and I need to evaluate it on the solution F0 which would take my whole life to compute at this rate.
Here is my code, if someone can tell me if I am doing something wrong that would be awesome:
using ForwardDiff, DifferentialEquations, LinearAlgebra, Plots, FiniteDifferences
Di = 1.
De = Di
ni = -5.
ne = ni # parameters
ti = 10.
te = ti
tsi = 1.
tse = 1.
Jei = 15.
Jie = Jei
Ii = 0.
Ie = 10.
args = [ Di, De, ni, ne, ti, te, Ii, Ie, tsi, tse, Ji, Je ]
g0 = [ 0.04629790429840539
1.611468284549182
0.12483580053806043
0.008700946777282085
-1.5185752607786998
0.5137968475438063 ] #initialization
F0(x) = [ De/(pi*te^2) + (2/te)*x[1]*x[2]; #Vector Field
1/te*(x[2]^2 + ne - (te*pi*x[1])^2 - te*x[3] + Ie);
1/tse*(-x[3] + Jei*x[4]);
Di/(pi*ti^2) + (2/ti)*x[4]*x[5];
1/ti*(x[5]^2 + ni - (ti*pi*x[4])^2 + ti*x[6] + Ii);
1/tsi*(-x[6] + Jie*x[1]) ]
F1(x) = [ 0; 1; 0; 0; 1; 0 ] #Vector field supporting the control
DF0(x)=FiniteDifferences.jacobian(central_fdm(5,1), F0, x)[1]
F01(x) = DF0(x)*F1(x) #1st bracket
DF01(x)=FiniteDifferences.jacobian(central_fdm(5,1), F01, x)[1]
F001(x) = DF0(x)*F01(x) - DF01(x)*F0(x) #2nd bracket
DF001(x)=FiniteDifferences.jacobian(central_fdm(5,1), F001, x)[1]
F0001(x) = DF0(x)*F001(x) - DF001(x)*F0(x) #3rd bracket
DF0001(x)=FiniteDifferences.jacobian(central_fdm(5,1), F0001, x)[1]
F00001(x) = DF0(x)*F0001(x) - DF0001(x)*F0(x) #4th bracket
DF00001(x)=FiniteDifferences.jacobian(central_fdm(5,1), F00001, x)[1]
F000001(x) = DF0(x)*F00001(x) - DF00001(x)*F0(x) #5th bracket
detF(x)=det([ F1(x) F01(x) F001(x) F0001(x) F00001(x) F000001(x) ]) #determinant
My function detF which computes the discriminant takes ages to compute:
x = rand(6)
@time detF(x)
I get : 6628.461385 seconds (140.90 G allocations: 3.975 TiB, 9.67% gc time, 0.10% compilation time)
6.126137843264654e8
From what I understand, using anonymous functions to save storage could accelerate the process? Any suggestion?
Thank you!
PS: if anyone’s curious, the dynamics is a meanfield model for populations of neurons, I’m trying to control them around their periodic orbit