Plotting a phase portrait of a differential equation

And with little bit more of extra work you can even get something like this:

using Makie 
using AbstractPlotting
using AbstractPlotting.MakieLayout
AbstractPlotting.inline!(true)
testField(x,y) = Point(-x, 2y)
x =  -2:0.1:2
y =  -2:0.1:2
u(x,y) = -x
v(x,y) = 2y
z = [log10(sqrt(u(x,y)^2 + v(x,y)^2)) for x in x, y in y]

scene, layout = layoutscene(resolution = (500, 400))
ax = layout[1, 1] = LAxis(scene, aspect = DataAspect(), 
    xlabel = "u", ylabel = "v", xticklabelsize=14, yticklabelsize=14)
fs = heatmap!(ax, x, y, z, colormap = :magma)
streamplot!(ax, testField, x, y, colormap = :magma,
    gridsize= (32,32), arrow_size = 0.04)
limits!(ax, -2, 2, -2, 2)
cbar = layout[1,2] = LColorbar(scene, fs, label = "log10[(u²+v²)½]", 
    labelsize = 14, ticklabelsize=14)
cbar.width = 12
cbar.height = Relative(3.7/4)
scene
save("odeField2.png", scene)

odeField2

More examples are easy to generate. Take for instance the analysis of limit cycles’s stability

using Makie 
using AbstractPlotting
using AbstractPlotting.MakieLayout
AbstractPlotting.inline!(true)

nonStablePoincare(x,y) = Point(x*(x^2+y^2-1) - y*(x^2+y^2+1),y*(x^2+y^2-1) + x*(x^2+y^2+1))
stableVanDerPaul(x,y) = Point(y, (1-x^2)*y -x)
semiStable(x,y) = Point(-y+ x*(-1+x^2+y^2)^2, x+y*(-1+x^2+y^2)^2) 

scene, layout = layoutscene(resolution = (900, 400))
ax1 = layout[1, 1] = LAxis(scene, aspect = DataAspect(), 
    xlabel = "x", ylabel = "y", title = "non-stable")
ax2 = layout[1, 2] = LAxis(scene, aspect = DataAspect(), 
    xlabel = "x", title = "stable")
ax3 = layout[1, 3] = LAxis(scene, aspect = DataAspect(),
    xlabel = "x", title = "semi-stable")

streamplot!(ax1, nonStablePoincare, -4..4, -4..4, colormap = :plasma, 
    gridsize= (32,32), arrow_size = 0.07)

streamplot!(ax2, stableVanDerPaul, -4..4, -4..4, colormap = :viridis, 
    gridsize= (32,32), arrow_size = 0.07)
streamplot!(ax3, semiStable, -4..4, -4..4, colormap = :rainbow1, 
    gridsize= (32,32), arrow_size = 0.07)
hideydecorations!(ax2, grid = false)
hideydecorations!(ax3, grid = false)
limits!(ax1, -4, 4, -4, 4)
limits!(ax2, -4, 4, -4, 4)
limits!(ax3, -4, 4, -4, 4)
scene
save("odeField3.png", scene)

25 Likes