This is a code for the function lyapunovs [link attached] in ChaosTools.jl .
The code below is a bit modified as I am using r=[1.0,1.0]
here instead of r=copy(get_state(pinteg,2)
for debugging purposes. I have tried r=deepcopy(get_state(pinteg,2)
as well and yet this is happening . As far as I know, by using deepcopy
this r should be independent and should only change in the rescale
function where I am passing it.
t0 = pinteg.t
# array to preallocate state for rescale
r = [1.0,1.0]#deepcopy(pinteg.u[1])#copy(pinteg.u[2])
while pinteg.t < t0 + Ttr
step!(pinteg, Δt)
d = λdist(pinteg)
lt ≤ d ≤ ut || rescale!(pinteg, d/d0, r)
end
t0 = pinteg.t
d = λdist(pinteg)
d == 0 && error("Initial distance between states is zero!!!")
rescale!(pinteg, d/d0, r)
λ = zero(d)
while pinteg.t < t0 + T
d = λdist(pinteg)
#evolve until rescaling:
while lt ≤ d ≤ ut
step!(pinteg, Δt)
d = λdist(pinteg)
pinteg.t ≥ t0 + T && break
end
# local lyapunov exponent is simply the relative distance of the trajectories
a = d/d0
λ += log(a)
rescale!(pinteg, a, r)
end
I define a variable r=[1.0,1.0]
. However, r is getting updated when the step!
function is being called. r
is not being referenced as far as I can see in the step function but still somehow it is changing. This seems like odd behavior to me, maybe I am making a silly mistake. I was trying to visualize why this using the debugger and I cannot understand why this is happening. Any advice on debugging this would be super helpful.
I am attaching a gif showing this in the debugger below