Phase portrait with vector field

It’s usually a mistake to make a “meshgrid” in julia…

quiver takes in 4 vectors, and has signature quiver(x, y, quiver = (u, v)). x and y are vectors of x-y coordinates. It will also accept a vector of 2-Tuples (each one being a point), or an Nx2 matrix. u and v must also be vectors, representing the x and y offset of each arrow in the quiver. You have all 4 being NxN matrices.

Given how you’ve set things up (with a meshgrid), you could recover the vectors you need by calling vec on x, y, u and v. In general though, it is better not to use a meshgrid in the first place and just iterate over the product of x and y with e.g. iterators.product(x, y), or using a nested for loop, or something similar.

Using vec, I get what I assume you were looking for:
quiver(vec(X), vec(Y), quiver=(vec(u), vec(v)), color="blue", alpha=0.5, aspect_ratio=:equal, framestyle=:box)

1 Like