% phase plot of 2d system with two critical points

f = @(t,x) [x(2); -x(1) - x(1)^2 - x(2)];

y1 = linspace(-1.5,.5,20);
y2 = linspace(-1,1,20);
[x,y] = meshgrid(y1,y2);

u = zeros(size(x));
v = zeros(size(x));

t=0;
for i = 1:numel(x)
    dx = f(t,[x(i); y(i)]);
    u(i) = dx(1);
    v(i) = dx(2);
end

quiver(x,y,u,v,'r'); figure(gcf)
xlabel('x_1')
ylabel('x_2')
axis tight equal;

hold on
for x = -1.5:0.25:0.5
  for y = -1:0.25:1
    [ts,ys] = ode45(f,[0,5],[x;y]);
    plot(ys(:,1),ys(:,2))
  end
end
hold off