Skip to content

Commit

Permalink
Generalise degenerate Lagrangians.
Browse files Browse the repository at this point in the history
  • Loading branch information
michakraus committed Dec 5, 2024
1 parent 7c2ddef commit a2e47ef
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/lagrangian_degenerate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct DegenerateLagrangianSystem
equations
functions

function DegenerateLagrangianSystem(θ, H, t, x, v, params = NamedTuple())
function DegenerateLagrangianSystem(K, H, t, x, v, params = NamedTuple())

@assert eachindex(x) == eachindex(v)

Expand All @@ -27,11 +27,10 @@ struct DegenerateLagrangianSystem

= collect(Dt.(x))

K = θ v
L = K - H
EL = [expand_derivatives(Dx[i](L) - Dt(Dv[i](L))) for i in eachindex(Dx,Dv)]
∇H = [expand_derivatives(dx(H)) for dx in Dx]
ϑ = [expand_derivatives(dv(L)) for dv in Dv]
ϑ = [expand_derivatives(dv(K)) for dv in Dv]
f = [expand_derivatives(dx(L)) for dx in Dx]
u = [u for u in ẋ]
g = [expand_derivatives(Dt.(ϑ))]
Expand Down
7 changes: 4 additions & 3 deletions test/lagrangian_lotka_volterra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ using LinearAlgebra
using Test


H(t, x, v, params) = params.a₁ * x[1] + params.a₂ * x[2] + params.b₁ * log(x[1]) + params.b₂ * log(x[2])
L(t, x, v, params) = log(x[2]) / x[1] / 2 * v[1] - log(x[1]) / x[2] / 2 * v[2] - H(t,x,v,params)
ϑ(t, x, v, params) = [log(x[2]) / x[1] / 2, - log(x[1]) / x[2] / 2]
H(t, x, v, params) = params.a₁ * x[1] + params.a₂ * x[2] + params.b₁ * log(x[1]) + params.b₂ * log(x[2])
K(t, x, v, params) = ϑ(t, x, v, params) v
L(t, x, v, params) = K(t, x, v, params) - H(t,x,v,params)

dHd₁(t, q, params) = params.a₁ + params.b₁ / q[1]
dHd₂(t, q, params) = params.a₂ + params.b₂ / q[2]
Expand Down Expand Up @@ -93,7 +94,7 @@ f̃(ṗ₂, t₀, q₀, v₀, params)

# DegenerateLagrangianSystem

deg_lag_sys = DegenerateLagrangianSystem(ϑ(t,x,v,sparams), H(t,x,v,sparams), t, x, v, sparams)
deg_lag_sys = DegenerateLagrangianSystem(K(t,x,v,sparams), H(t,x,v,sparams), t, x, v, sparams)

q̇₁, q̇₂ = zero(q₀), zero(q₀)
p₁, p₂ = zero(p₀), zero(p₀)
Expand Down

0 comments on commit a2e47ef

Please sign in to comment.