Plotting differential equation solutions

The following code runs really slowly, because it redraws the graph every update, instead of incrementally. There must be some method for incremental diagramming, but I can’t find any.

There should be a way to plot this directly in the library, too. Maybe I should put this in a feature request?

using DifferentialEquations, ParameterizedFunctions
van! = @ode_def VanDerPol begin
  dy = μ*((1-x^2)*y - x)
  dx = 1*y
end μ

prob = ODEProblem(van!, [0.0,2.0], (0.0,6.3), p=1e2)
sol = solve(prob)
@gif for t in 0:0.01:5
    xys = reduce(hcat, sol.(0:0.01:t))
    xs = xys[1,:]
    ys = xys[2,:]
    plot(xs, ys)
    scatter!([(last(xs), last(ys))])

van de Pol graph

For faster animations you should try using Makie.jl, since indeed Plots.jl has to remake the whole plots. We do not have recipes with Makie.jl yet though.

1 Like