How to draw a phase portrait of a system of differential equations

Hi all,

I have this uncoupled linear system

\dot{x}_{1} = -x_{1}

\dot{x}_{2} = 2x_{2}

the system can be written in matrix form as

\dot{x} = Ax

with A = [-1 \ 0; 0 \ 2]

the general solution are:

x_{1} (t) = c_{1} e^{-t}

x_{2} (t) = c_{2} e^{2t}


x(t) = [e^{-t} \ 0; 0 \ e^{2t}]c

in the book they draw the phase portrait as below:
Capture d’écran_2022-10-29_20-44-58

My question is how to draw such phase portrait?


For example like this with Makie: streamplot

1 Like

Is there any way to use CairoMakie in REPL and save the image as png, instead of using Jupyter Notebook / IJulia?

I need to add

using Meshes

but the codes do not work:

Function passed to streamplot must return Point2 or Point3

** [1] error(s::String)**
** @ Base ./error.jl:33**
** [2] streamplot_impl(CallType::Type, f::typeof(f), limits::Rect2D{Float64}, resolutionND::Tuple{Int64, Int64, Int64}, stepsize::Float64, maxsteps::Int64, dens::Float64)**
** @ Makie ~/.julia/packages/Makie/c5WJV/src/basic_recipes/streamplot.jl:112**
** [3] (::Makie.var"#611#616")(f::Function, limits::Rect2D{Float64}, resolution::Tuple{Int64, Int64, Int64}, stepsize::Float64, maxsteps::Int64, density::Float64)**
** @ Makie ~/.julia/packages/Makie/c5WJV/src/basic_recipes/streamplot.jl:167**

I am trying this code but can’t work to save the image as svg, which line do i miss?

using CairoMakie

struct FitzhughNagumo{T}

P = FitzhughNagumo(0.1, 0.0, 1.5, 0.8)

f(x, P::FitzhughNagumo) = Point2f(
    P.γ*x[1]-x[2] + P.β

f(x) = f(x, P)

streamplot(f, -1.5..1.5, -1.5..1.5, colormap = :magma)


This is the reason. It’s a simple fix, best share your code