Created
July 30, 2020 22:40
-
-
Save YingboMa/c9f1e2c2210f35d60d1f68a0cfe806a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using DiffEqDevTools, BifurcationKit, Setfield, Plots | |
mutable struct TermCache | |
start | |
sign::Bool | |
count::Int | |
end | |
function stability_curve(tab) | |
function curve((x, ), (y, )) | |
sol = stability_region(x+y*im, tab) | |
[abs(sol) - 1] | |
end | |
cache = TermCache(nothing, true, 0) | |
function terminate(z, tau, step, contResult) | |
if step == 1 | |
cache.start = z.p | |
elseif step == 2 | |
cache.sign = cache.start - z.p > 0 | |
else | |
if (cache.start - z.p > 0) != cache.sign | |
cache.sign = !cache.sign | |
cache.count += 1 | |
end | |
return cache.count <= 1 | |
end | |
return true | |
end | |
sol, _ = BifurcationKit.continuation(curve, [-0.1,], [0.0], (@lens _[1]), ContinuationPar(pMin=-80.0, pMax=80.0, maxSteps=1000); finaliseSolution = terminate) | |
return sol | |
end | |
sol_tsit5 = stability_curve(constructTsitouras5()) | |
plot(sol_tsit5.branch[2, :], sol_tsit5.branch[1, :]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment