@@ -36,6 +36,7 @@ function interactive_cobweb(
3636
3737@assert O ≥ 1
3838@assert DynamicalSystems. dimension (ds) == 1
39+ @assert ! DynamicalSystems. isinplace (ds)
3940
4041figure = Figure (resolution = (1000 , 800 ))
4142axts = figure[1 , :] = Axis (figure)
@@ -44,7 +45,7 @@ axmap = figure[2, :] = Axis(figure)
4445sg = SliderGrid (figure[3 , :],
4546 (label = pname, range = prange),
4647 (label = " n" , range = 1 : Tmax, startvalue = 20 ),
47- (label = " x₀" , range = x0s, startvalue = ds . u0 ),
48+ (label = " x₀" , range = x0s, startvalue = DynamicalSystems . initial_state (ds)[ 1 ] ),
4849)
4950r_observable, L, x0 = [sg. sliders[i]. value for i in 1 : 3 ]
5051
@@ -54,7 +55,14 @@ function seriespoints(x)
5455 return [Point2f (n[i], x[i]) for i in 1 : length (x)]
5556end
5657
57- x = Observable (DynamicalSystems. trajectory (ds, L[], x0[]))
58+ function get_float_trajectory (ds, L, x0)
59+ y = x0 isa Real ? DynamicalSystems. SVector (x0) : x0
60+ z = DynamicalSystems. trajectory (ds, L, y)[1 ]
61+ w = reinterpret (Float64, vec (z))
62+ return Float32 .(w)
63+ end
64+
65+ x = Observable (get_float_trajectory (ds, L[], x0[]))
5866xn = lift (a -> seriespoints (a), x)
5967lines! (axts, xn; color = trajcolor, lw = 2.0 )
6068scatter! (axts, xn; color = trajcolor, markersize = 10 )
@@ -64,9 +72,14 @@ ylims!(axts, xmin, xmax)
6472# Cobweb diagram
6573DynamicalSystems. set_parameter! (ds, pindex, prange[1 ])
6674
67- fobs = Any[Observable (ds. f .(xs, Ref (ds. p), 0 ))]
75+ fobs = Any[Observable (
76+ map (x -> DynamicalSystems. dynamic_rule (ds)(x, DynamicalSystems. current_parameters (ds), 0 )[1 ], xs)
77+ )]
6878for order in 2 : O
69- push! (fobs, Observable (ds. f .(fobs[end ][], Ref (ds. p), 0 )))
79+ push! (fobs, Observable (
80+ map (x -> DynamicalSystems. dynamic_rule (ds)(x, DynamicalSystems. current_parameters (ds), 0 )[1 ], fobs[end ][])
81+ # DynamicalSystems.dynamic_rule(ds).(fobs[end][], Ref(DynamicalSystems.current_parameters(ds)), 0)
82+ ))
7083end
7184
7285# plot diagonal and fⁿ
@@ -87,20 +100,23 @@ ylims!(axmap, xmin, xmax)
87100# On trigger r-slider update all plots:
88101on (r_observable) do r
89102 DynamicalSystems. set_parameter! (ds, pindex, r)
90- x[] = DynamicalSystems . trajectory (ds, L[], x0[])
91- fobs[1 ][] = ds . f .(xs, Ref (ds. p ), 0 )
103+ x[] = get_float_trajectory (ds, L[], x0[])
104+ fobs[1 ][] = map (x -> DynamicalSystems . dynamic_rule (ds)(x, DynamicalSystems . current_parameters (ds), 0 )[ 1 ], xs )
92105 for order in 2 : O
93- fobs[order][] = ds. f .(fobs[order- 1 ][], Ref (ds. p), 0 )
106+ fobs[order][] = map (
107+ x -> DynamicalSystems. dynamic_rule (ds)(x, DynamicalSystems. current_parameters (ds), 0 )[1 ], fobs[order- 1 ][]
108+ )
94109 end
95110end
96111
97112on (L) do l
98- x[] = DynamicalSystems. trajectory (ds, l, x0[])
113+ res = get_float_trajectory (ds, l, x0[])
114+ x[] = res
99115 xlims! (axts, 0 , l) # this is better than autolimits
100116end
101117
102118on (x0) do u
103- x[] = DynamicalSystems . trajectory (ds, L[], u)
119+ x[] = get_float_trajectory (ds, L[], u)
104120end
105121
106122# Finally add buttons to hide/show elements of the plot
0 commit comments