# Can not choose alg for lyapunovspectrum DynamicalSystems.jl

I have system and parametres:

``````function HR!(du, u, p, t)

function sigma(x)
return 1.0 / ( 1.0 + exp( -10.0 * ( x  - ( - 0.25 ) ) ) )
end

a, b, c, d, s, xr, r,  I, vs, k1, k2, el_link  = p
x1, y1, z1, x2, y2, z2 = u

du = y1 + b * x1 ^ 2 - a * x1 ^3 - z1 + I - k1 * ( x1 - vs ) * sigma(x2) + el_link * ( x2 - x1 )
du = c - d * x1 ^2 - y1
du = r * ( s * ( x1 - xr ) - z1 )

du = y2 + b * x2 ^ 2 - a * x2 ^3 - z2 + I - k2 * ( x2 - vs ) * sigma(x1) + el_link * ( x1 - x2 )
du = c - d * x2 ^2 - y2
du = r * ( s * ( x2 - xr ) - z2 )

return SVector(du, du, du,
du, du, du)
end

tspan = (0., 50000.)

a = 1.
b = 3.
c = 1.
d = 5.
xr = -1.6
r = 0.01 # 0.01
s = 5.
I = 4.
xv = 2.

k1= -0.17
k2 = k1
``````

I try calculate lyapunov spectrum with this code

``````p = [a, b, c, d,
s, xr, r, I, xv, k1, k2, 0]
initialcondition = [-0.469412067339509, -0.5839635169884322, 4.025111076102515, -0.469412067339509, -0.5839635169884322, 4.025111076102515]
ds_HR = ContinuousDynamicalSystem(HR!, initialcondition, p )

spectrum = lyapunovspectrum(ds_HR, tspan; diffeq = (alg = AutoVern9(Rodas5()), maxiters = 10000000))
``````

and get next error:

Please see Please read: make it easier to help you and update the post accordingly in order to get an answer quicker (my bet is that when you defined the dynamic rule you annotated types)

1 Like

I updated, sorry

what happens when you do `integrator(ds)` and then `step!(integ)`?

I was randomly able to correct this error. Why that fixed i don’t understand

May I ask one more slightly off-topic question, so as not to create a new topic? It is related to the Lyapunov spectrum

sure, also consider joining the `dynamics-bridged` channel on the julia slack

Okay, thank you. I read about reinit! but i don’t understand how correctly used him for this code

``````for (i, k) in enumerate(k_space)
if i == 1
global initialcondition = [-1.5, 0.0, 0.0, -2.5, 0.0, 0.0] # [0.1, 0.2, 0.3, 0.4, 0.05, 0.6]
end
println("Initial condition: \$initialcondition"); flush(stdout)
println("k: \$k"); flush(stdout)

p = [a, b, c, d,
s, xr, r, I, xv, k1, k2, k]
prob = ODEProblem(HR!, initialcondition, tspan, p)
sol = solve(prob, AutoVern9(Rodas5()), abstol = 1e-11, reltol = 1e-11, maxiters = 10000000)

ds_HR = ContinuousDynamicalSystem(HR!, initialcondition, p )
spectrum = lyapunovspectrum(ds_HR, tspan; diffeq = (alg = AutoVern9(Rodas5()), abstol = 1e-11, reltol = 1e-11, maxiters = 10000000))
spectrum_array[1:3, i] = spectrum[1:3]

println("Spectrum: ", spectrum_array[1:3, i]); flush(stdout)

initialcondition = sol[length(sol.u)]

println("Last point: ", initialcondition); flush(stdout)

println(">>>>>>>>>>>>>>>"); flush(stdout)
println(""); flush(stdout)

end
``````

This evolution of lyapunov sprectrum with inheritance of initial conditions and change of one parameter

Okay, thank you.