From 9eec6501051bf191c0493fafb789671f3970c949 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Tue, 26 Jun 2018 17:37:35 -0700 Subject: [PATCH 1/6] Add examples/bazykin_85.md --- docs/mkdocs.yml | 1 + docs/src/examples.md | 1 + docs/src/examples/bazykin_85.md | 65 +++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 docs/src/examples/bazykin_85.md diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index bfd5192..03d6179 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -27,3 +27,4 @@ pages: - examples.md - examples/calcium.md - examples/van_der_pol.md + - examples/bazykin_85.md diff --git a/docs/src/examples.md b/docs/src/examples.md index 049d616..cb0ef7e 100644 --- a/docs/src/examples.md +++ b/docs/src/examples.md @@ -4,5 +4,6 @@ Pages = [ "examples/calcium.md", "examples/van_der_pol.md", + "examples/bazykin_85.md", ] ``` diff --git a/docs/src/examples/bazykin_85.md b/docs/src/examples/bazykin_85.md new file mode 100644 index 0000000..f445500 --- /dev/null +++ b/docs/src/examples/bazykin_85.md @@ -0,0 +1,65 @@ +# Bazykin's predator-prey system + +```@example bazykin85 +using Bifurcations +using Bifurcations.Examples: Bazykin85 + +solver = init(Bazykin85.prob) +solve!(solver) +``` + +Plot codimension-one bifurcations: + +```@example bazykin85 +using Plots +using Bifurcations: plot # workaround + +plt1 = plot(solver.sol) +savefig(plt1, "bazykin85-1.png"); nothing # hide +``` + +![](bazykin85-1.png) + +Let's follow the Hopf and Saddle-Node bifurcations: + +```@example bazykin85 +using Bifurcations: special_points +using Setfield: @lens + +point_list = sort!(special_points(solver), by=p->p.u0[end]) + +codim2_solvers = [] +for point in point_list[2:3] + @show point + + codim2_prob = BifurcationProblem( + point, + solver, + (@lens _.δ), + (0.0, 10.0), + ) + codim2_solver = init( + codim2_prob; + # h0 = 0.001, + nominal_angle_rad = 0.01, + max_samples = 1000, + ) + push!(codim2_solvers, codim2_solver) + solve!(codim2_solver) + + @show codim2_solver +end +``` + +Merge two continuations and draw the bifurcation diagram: + +```@example bazykin85 +plt2 = plot() +for s in codim2_solvers + n = length(s.sol.sweeps[1].super.u[1]) + plot!(plt2, s.sol, vars=(n - 1, n)) +end +savefig(plt2, "bazykin85-2.png"); nothing # hide +``` + +![](bazykin85-2.png) From 553dd3a2db1dedb6aab0b7b5e764402a2cd05a43 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Tue, 26 Jun 2018 17:37:35 -0700 Subject: [PATCH 2/6] Add examples/bazykin_85.md --- docs/src/examples/bazykin_85.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/src/examples/bazykin_85.md b/docs/src/examples/bazykin_85.md index f445500..ea701f6 100644 --- a/docs/src/examples/bazykin_85.md +++ b/docs/src/examples/bazykin_85.md @@ -40,7 +40,6 @@ for point in point_list[2:3] ) codim2_solver = init( codim2_prob; - # h0 = 0.001, nominal_angle_rad = 0.01, max_samples = 1000, ) From 8720ed9f7ec77d932520de032fffa06becb3ce8c Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Wed, 11 Jul 2018 12:37:22 -0700 Subject: [PATCH 3/6] Fix imports in examples/bazykin_85.md --- docs/src/examples/bazykin_85.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/examples/bazykin_85.md b/docs/src/examples/bazykin_85.md index ea701f6..b431406 100644 --- a/docs/src/examples/bazykin_85.md +++ b/docs/src/examples/bazykin_85.md @@ -11,8 +11,8 @@ solve!(solver) Plot codimension-one bifurcations: ```@example bazykin85 +using Bifurcations: plot, plot! # workaround using Plots -using Bifurcations: plot # workaround plt1 = plot(solver.sol) savefig(plt1, "bazykin85-1.png"); nothing # hide From e82eae49aa41017bff784fab656692eff026f0b8 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Wed, 11 Jul 2018 12:52:28 -0700 Subject: [PATCH 4/6] Demonstrate switch via Bogdanov-Takens bifurcation --- docs/src/examples/bazykin_85.md | 36 +++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/docs/src/examples/bazykin_85.md b/docs/src/examples/bazykin_85.md index b431406..1048440 100644 --- a/docs/src/examples/bazykin_85.md +++ b/docs/src/examples/bazykin_85.md @@ -23,13 +23,18 @@ savefig(plt1, "bazykin85-1.png"); nothing # hide Let's follow the Hopf and Saddle-Node bifurcations: ```@example bazykin85 -using Bifurcations: special_points +using Bifurcations: Codim1, special_points using Setfield: @lens -point_list = sort!(special_points(solver), by=p->p.u0[end]) +sn_point, = sort!( + special_points(solver, Codim1.PointTypes.saddle_node), + by=p->p.u0[1]) +hopf_point, = special_points(solver, Codim1.PointTypes.hopf) + +point_list = [sn_point, hopf_point] codim2_solvers = [] -for point in point_list[2:3] +for point in point_list @show point codim2_prob = BifurcationProblem( @@ -48,9 +53,32 @@ for point in point_list[2:3] @show codim2_solver end + +sn_solver1, hopf_solver1 = codim2_solvers + +nothing # hide +``` + +Switch to Hopf bifurcation via Bogdanov-Takens bifurcation: + +```@example bazykin85 +using Bifurcations: Codim2 +bt_point, = sort( + special_points(sn_solver1, + Codim2.PointTypes.bogdanov_takens); + by = p -> p.u0[end - 1], # α + rev = true) +hopf_prob = BifurcationProblem(bt_point, sn_solver1) +hopf_solver2 = init(hopf_prob) +solve!(hopf_solver2) +@show hopf_solver2 + +push!(codim2_solvers, hopf_solver2) + +nothing # hide ``` -Merge two continuations and draw the bifurcation diagram: +Merge continuations and draw the bifurcation diagram: ```@example bazykin85 plt2 = plot() From 312db2b9d6c648cea36dfa79973e23dc0bd2fb4c Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Wed, 11 Jul 2018 12:38:53 -0700 Subject: [PATCH 5/6] Resolve points when plotting Codim2Solver --- docs/src/examples/bazykin_85.md | 2 +- src/plotting.jl | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/src/examples/bazykin_85.md b/docs/src/examples/bazykin_85.md index 1048440..34215cb 100644 --- a/docs/src/examples/bazykin_85.md +++ b/docs/src/examples/bazykin_85.md @@ -84,7 +84,7 @@ Merge continuations and draw the bifurcation diagram: plt2 = plot() for s in codim2_solvers n = length(s.sol.sweeps[1].super.u[1]) - plot!(plt2, s.sol, vars=(n - 1, n)) + plot!(plt2, s, vars=(n - 1, n)) end savefig(plt2, "bazykin85-2.png"); nothing # hide ``` diff --git a/src/plotting.jl b/src/plotting.jl index 67603a3..40eb83a 100644 --- a/src/plotting.jl +++ b/src/plotting.jl @@ -438,7 +438,8 @@ function plot!(plt, BifurcationSolution, BifurcationSolver}, args...; - resolve_points = plottable isa Codim1Solver, + resolve_points = plottable isa Union{Codim1Solver, + Codim2Solver}, include_points = !(plottable isa Codim1LCSolver), # TODO: don't vars = length(args) > 0 ? nothing : default_vars(plottable), bif_style = STYLE, From 6a752f442c489926c09631c6e07c119aed389c34 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Mon, 16 Jul 2018 21:17:04 -0700 Subject: [PATCH 6/6] Demonstrate switch via Bautin bifurcation --- docs/src/examples/bazykin_85.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/docs/src/examples/bazykin_85.md b/docs/src/examples/bazykin_85.md index 34215cb..175ab9f 100644 --- a/docs/src/examples/bazykin_85.md +++ b/docs/src/examples/bazykin_85.md @@ -78,6 +78,33 @@ push!(codim2_solvers, hopf_solver2) nothing # hide ``` +Switch to the fold bifurcation of limit cycle via Bautin bifurcation: + +```@example bazykin85 +using Bifurcations: Codim2 +using Bifurcations.Codim2LimitCycle: FoldLimitCycleProblem +bautin_point_list = special_points(hopf_solver2, Codim2.PointTypes.bautin) +@assert length(bautin_point_list) == 1 +bautin_point, = bautin_point_list +flc_prob = FoldLimitCycleProblem( + bautin_point, + hopf_solver2; + num_mesh = 20, + degree = 3, +) +flc_solver = init( + flc_prob; + start_from_nearest_root = true, + max_branches = 0, +) +solve!(flc_solver) +@show flc_solver + +push!(codim2_solvers, flc_solver) + +nothing # hide +``` + Merge continuations and draw the bifurcation diagram: ```@example bazykin85