Skip to content

Commit

Permalink
Merge pull request #69 from ErikQQY/lyapunovwithparameters
Browse files Browse the repository at this point in the history
Add parameters specification for lyapunov exponents
  • Loading branch information
ErikQQY committed Apr 28, 2023
2 parents 1e10137 + 4c72af0 commit 56a33c4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/lyapunov.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,23 @@ Computing fractional order Lyapunov exponent of a fractionl order system.
}
```
"""
function FOLyapunov(fun, order, t_start, h_norm, t_end, u0, h, out)
function FOLyapunov(fun, order, t_start, h_norm, t_end, u0, h, out, p)
if is_all_equal(order)

LE = commensurate_lyapunov(fun, order, t_start, h_norm, t_end, u0, h, out)
LE = commensurate_lyapunov(fun, order, t_start, h_norm, t_end, u0, h, out, p)
else
LE = noncommensurate_lyapunov(fun, order, t_start, h_norm, t_end, u0, h, out)
LE = noncommensurate_lyapunov(fun, order, t_start, h_norm, t_end, u0, h, out, p)
end
return LE

end

# Dispatch for parameters not specified
FOLyapunov(fun, order, t_start, h_norm, t_end, u0, h, out) = FOLyapunov(fun, order, t_start, h_norm, t_end, u0, h, out, nothing)

#FOLyapunov(sys::FODESystem, h_norm, h, out) = FOLyapunov(sys.f, sys.α, sys.tspan[1], h_norm, sys.tspan[2], sys.u0, h, out)
FOLyapunov(sys::FODESystem, h_norm, h, out, p) = FOLyapunov(sys.f, sys.α, sys.tspan[1], h_norm, sys.tspan[2], sys.u0, h, out, p)
FOLyapunov(sys::FODESystem, h_norm, h, out) = FOLyapunov(sys.f, sys.α, sys.tspan[1], h_norm, sys.tspan[2], sys.u0, h, out, nothing)

@inline function is_all_equal(order::AbstractArray)
length(order) < 2 && return true
element1 = order[1]
Expand All @@ -34,7 +40,7 @@ end
return true
end

function noncommensurate_lyapunov(fun, order, t_start, h_norm, t_end, u0, h, out)# TODO: Generate the Lyapunov exponent plot
function noncommensurate_lyapunov(fun, order, t_start, h_norm, t_end, u0, h, out, p)# TODO: Generate the Lyapunov exponent plot
ne::Int = length(u0) # System dimension

tspan = Float64[]
Expand Down Expand Up @@ -63,7 +69,7 @@ function noncommensurate_lyapunov(fun, order, t_start, h_norm, t_end, u0, h, out
t = t_start
LExp = zeros(ne)
for it=1:n_it
prob = FODESystem(extend_fun, q[:], x[:], (t, t+h_norm))
prob = FODESystem(extend_fun, q[:], x[:], (t, t+h_norm), p)
sol = solve(prob, h, PECE())
Y = sol.u
t = t+h_norm
Expand Down Expand Up @@ -130,7 +136,7 @@ function jacobian_of_fdefun(f, t, y, p)
end
end

function commensurate_lyapunov(fun, order, t_start, h_norm, t_end, u0, h, out)# TODO: Generate the Lyapunov exponent plot
function commensurate_lyapunov(fun, order, t_start, h_norm, t_end, u0, h, out, p)# TODO: Generate the Lyapunov exponent plot
ne::Int = length(u0) # System dimension
order = order[1] # Since this is the commensurate case, we only need one element in order array

Expand Down Expand Up @@ -221,9 +227,6 @@ function commensurate_lyapunov(fun, order, t_start, h_norm, t_end, u0, h, out)#
return FOLE(tspan, LE)
end

#FOLyapunov(sys::FODESystem, h_norm, h, out) = FOLyapunov(sys.f, sys.α, sys.tspan[1], h_norm, sys.tspan[2], sys.u0, h, out)
FOLyapunov(sys::FODESystem, h_norm, h, out) = FOLyapunov(sys.f, sys.α, sys.tspan[1], h_norm, sys.tspan[2], sys.u0, h, out)

mutable struct M
an
bn
Expand Down
16 changes: 16 additions & 0 deletions test/FOLEtest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,20 @@ end
@test isapprox(LE.LE[end-2:end], [-0.0033493403496077058
-0.0050780674255360226
-1.774132087623718]; atol=1e-3)
end

@testset "Test Noncommensurate Lyapunov exponents with parameters specification" begin
function LE_RF_TEST(du, u, p, t)
a, b, c = p
du[1] = u[2]*(u[3]-a+u[1]^2) + b*u[1]
du[2] = u[1]*(3*u[3]+1-u[1]^2) + 0.1*u[2]
du[3] = -2*u[3]*(c+u[1]*u[2])
end

p = [1, 0.1, 0.98]

LE = FOLyapunov(LE_RF_TEST, [0.995, 0.992, 0.996], 0, 0.1, 1000, [1,1,1], 0.01, 1000, p)
@test isapprox(LE.LE[end-2:end], [-0.0033493403496077058
-0.0050780674255360226
-1.774132087623718]; atol=1e-3)
end

0 comments on commit 56a33c4

Please sign in to comment.