Direction fields for 2×2 systems

Here is the Sage code to produce a direction field for a 2×2 system of ODEs.


# v' = Av, A is 2x2 matrix
A = matrix([[-1/2,1],[-1,-1/2]]);
print 'You entered: A = ';
print A;
x,y = var('x,y');
intermediate_step = (A*vector([x,y])).normalized();
v_prime(x,y) = (intermediate_step[0],intermediate_step[1]);
plot_vector_field(v_prime(x,y), (x,-2,2), (y,-2,2))

If you haven’t already, go to sagenb.org, log in (you might should click the Google or Yahoo icon), open a new worksheet, copy paste this into a cell, and click “evaluate”. You should get a beautiful direction field.

Note, I’m finding that sagenb.org isn’t working the way it used to. If having trouble, you might try https://cloud.sagemath.com/ and create a new project and create a new Sage worksheet, then copy, paste, and run the code.