I want to check some Lyapunov functions for a dynamical system. In order to do that, I have the variables in my system: n1(t) - n4(t), and m(t), which define a set of coupled ODEs. I declare a (wannabe) Lyapunov function V(n, m).
Using the Julia package Symbolics, I input all of this into my system:
using Symbolics
using LinearAlgebra
N = 4
 = A-I
@variables t n(t)[1:N] m(t)
M = ones(Num, N, N)
M[1,2] = m
I also define the derivatives for all n[i] and m with respect to time, as discussed in the Symbolics documentation:
# Define the derivatives dnᵢ(t)/dt
for i in 1:N
Symbolics.derivative(::typeof(n[i]), args::NTuple{1, Any}, ::Val{1}) = n[i]*(1+sum(Â[i,j] * M[i,j] * n[j](args[1]) for j in 1:N))
end
Symbolics.derivative(::typeof(m), args::NTuple{1, Any}, ::Val{1}) = ω*(1)(1 - m(args[1]) + β*n[3](args[1]))
Afterwards I define my Lyapunov function V, and get the derivatives:
function V(n, m)
M = ones(Num, N, N)
M[1,2] = m
return sum(log(-sum(Â[i,j] * M[i,j] * n[j] for j in 1:N)) for i in 1:N)
end
Dt = Differential(t)
DtV = Dt(V(n, m))
out = simplify(expand_derivatives(DtV))
# Print the derivative
println("dV/dt is $(out)")
The output from this is
The dV/dt is (Differential(t)((n(t))[2]) + Differential(t)((n(t))[3]) - Differential(t)((n(t))[1]) - Differential(t)((n(t))[4]))*(((n(t))[2] + (n(t))[3] - (n(t))[1] - (n(t))[4])^-1) + (Differential(t)((n(t))[1]) + Differential(t)((n(t))[2]) - Differential(t)((n(t))[3]) - Differential(t)((n(t))[4]))*(((n(t))[1] + (n(t))[2] - (n(t))[3] - (n(t))[4])^-1) + (Differential(t)((n(t))[1]) + Differential(t)((n(t))[3]) - Differential(t)((n(t))[4]) - m(t)*Differential(t)((n(t))[2]) - Differential(t)(m(t))*(n(t))[2])*(((n(t))[1] + (n(t))[3] - (n(t))[4] - m(t)*(n(t))[2])^-1) + (Differential(t)((n(t))[1]) + Differential(t)((n(t))[2]) + Differential(t)((n(t))[3]) + Differential(t)((n(t))[4]))*(((n(t))[1] + (n(t))[2] + (n(t))[3] + (n(t))[4])^-1)
This contains a lot of Differential(t)((n(t))[i]
. I already defined what this differential should be however. How can I make it expand all those Differential(t)((n(t))[i]
terms, so the end result is a function of my variables n and m?