PerezHz / TaylorIntegration.jl

ODE integration using Taylor's method, and more, in Julia
Other
127 stars 23 forks source link

function lyap_taylorinteg can't work #128

Closed Grotex closed 3 years ago

Grotex commented 3 years ago

Greetings.

When using lyap_taylorinteg to work out the Lyapunov spectrum of the Lorenz system, an error was throw out. (with Julia 1.6.1)

julia> using TaylorIntegration, TaylorSeries

julia> function lorenz!(t, x, dx) dx[1] = σ(x[2]-x[1]) dx[2] = x[1](ρ-x[3])-x[2] dx[3] = x[1]x[2]-βx[3] nothing end lorenz! (generic function with 1 method)

julia> const σ = 10.71 10.71

julia> const ρ = 119 119

julia> const β = 8.93 8.93

julia>

julia>

julia> const x0 = [19.0, 20.0, 50.0] 3-element Vector{Float64}: 19.0 20.0 50.0

julia> const t0 = 0.0 0.0

julia> const tmax = 100.0 100.0

julia> @time tv, xv, λv = lyap_taylorinteg(lorenz!, x0, t0, tmax, 28, 1e-20; maxsteps=2000000); ERROR: AssertionError: length(q0) must be equal to number of variables set by TaylorN Stacktrace: [1] lyap_taylorinteg(f!::Function, q0::Vector{Float64}, t0::Float64, tmax::Float64, order::Int64, abstol::Float64, params::Nothing, jacobianfunc!::Nothing; maxsteps::Int64, parse_eqs::Bool) @ TaylorIntegration C:\Users\gsjiang.julia\packages\TaylorIntegration\hUDy9\src\lyapunovspectrum.jl:241 [2] top-level scope @ .\timing.jl:210 [inlined] [3] top-level scope @ .\REPL[9]:0

Why this error occurs?

Grotex commented 3 years ago

ERROR: AssertionError: length(q0) must be equal to number of variables set by TaylorN

this is THE ERROR according to output result

PerezHz commented 3 years ago

Hi @Grotex!

Since lyap_taylorinteg is using TaylorN internally, this requires a call to set_variables before calling lyap_taylorinteg, e.g.:

xi = set_variables("δ", order=1, numvars=length(x0)) # variable name can be anything
# then, call lyap_taylorinteg...

Note that the order kwarg must be 1, and numvars must be equal to length(x0). We are keeping this out of lyap_taylorinteg since set_variables modifies certain global variables defined in TaylorSeries, so in this way this global variable modification is transparent to the user.

There's an example in the docs, which deals precisely with the Lyapunov spectrum for the Lorenz system.

cc: @lbenet

lbenet commented 3 years ago

In addition to the comment of @PerezHz, note that the function lorenz! you defined above does not follow the convention we use, which is the same as in DifferentialEquations. The arguments of that function should be du, u, p, t, where du is the left hand side of the ODEs, u are the dependent variables, p are parameters, and t is the independent variable (time).

lbenet commented 3 years ago

Does the example in the docs clarify this issue? Can we close it?

Grotex commented 3 years ago

Does the example in the docs clarify this issue? Can we close it?

OK, I understand. Close it.