Update non linear solve with sliders (Makie)

I would like to plot iwith GLMakie the solution of a non linear equation that I solve with the NonlinearSolve.jl package, but I would like this plot to be updated when I move a slider (the parameter of the equation is linked to this slider, and thus the solution found by NonlinearSolve).

I struggle to find a way : I can’t see how the “lift” command must be used in this case…

Try starting with something like this and report back with complete code if it doesn’t work:

using GLMakie, NonlinearSolve

# Lay out the display
fig = Figure()
ax = Axis(fig[1, 1])
sl = Slider(fig[2, 1], range = 0:0.01:10, startvalue = 3)

#define the problem
f(u, p) = u .* u .- p
u0 = [1.0, 1.0]
prob = NonlinearProblem(f, u0, [2])

# solve the problem and put the solution in a ready-to-plot format
points = lift(sl.value) do p
    newprob = remake(prob, p=[p])
    soln = solve(newprob)
    [Point(p, soln.u[1])]
end

# create the plot
scatter!(points, color = :red, markersize = 20)
# reset the limits to ensure the point is visible
limits!(ax, 0, 10, 0, 10)
# display the figure
fig
1 Like