Constructing Phase Planes

## Description

We can use a combination of commands to construct a phase plane for a system. We'll create a phase plane for the system

(1)
\begin{align} x' &= x + 3y\\ y' &= x - y \end{align}

We'll create our phase plane by combining plots of the vector field and nullclines $y = (-1/3)x$ and $y = x$

## Sage Cell

#### Code

var('x y')
vec = vector([x + 3*y, x - y])
mag = sqrt(vec^2 + vec^2)
p = plot_vector_field(vec/mag, (x, -5, 5), (y, -5, 5))
p += plot((-1/3)*x, (x, -6, 6)) + plot(x, (x, -6, 6), color='red')
p.show(xmin=-5, xmax=5, ymin=-5, ymax=5)


## Options

We can add a solution curve to our plot to see how a solution behaves under given initial conditions, using the desolve_system method. Be careful when adding a solution curve, as it may affect the bounds of the graph; you can easily remedy this by setting xmin, xmax, ymin or ymax as necessary when calling .show().

While we’re at it, if we know the straightline solutions, we may add those as well:

#### Code

var('t')
x = function('x')(t)
y = function('y')(t)
de1 = diff(x, t) == x + 3*y
de2 = diff(y, t) == x - y
sols = desolve_system([de1, de2], vars=[x, y], ivar=t, ics=[0, 1, 3])
curve = vector([sols.rhs(), sols.rhs()])
var('x y')
vec = vector([x + 3*y, x - y])
mag = sqrt(vec^2 + vec^2)
p = plot_vector_field(vec/mag, (x, -5, 5), (y, -5, 5))
p += plot((-1/3)*x, (x, -6, 6)) + plot(x, (x, -6, 6), color='red')
p += parametric_plot(curve, (t, 0, 10), color='green')
p.show(xmin=-5, xmax=5, ymin=-5, ymax=5)

var('t')
x = function('x')(t)
y = function('y')(t)
de1 = diff(x, t) == x + 3*y
de2 = diff(y, t) == x - y
sols = desolve_system([de1, de2], vars=[x, y], ivar=t, ics=[0, 1, 3])
curve = vector([sols.rhs(), sols.rhs()])
var('x y')
vec = vector([x + 3*y, x - y])
mag = sqrt(vec^2 + vec^2)
p = plot_vector_field(vec/mag, (x, -5, 5), (y, -5, 5))
p += plot((-1/3)*x, (x, -6, 6)) + plot(x, (x, -6, 6), color='red')
p += parametric_plot(curve, (t, 0, 10), color='green')
p += plot(-x, (x, -6, 6), color='purple') + plot((1/3)*x, (x, -6, 6), color='purple')
p.show(xmin=-5, xmax=5, ymin=-5, ymax=5)


## Tags

Primary Tags:

Secondary Tags:

A list of possible tags can be found at The WeBWorK Open Problem Library. For linear algebra tags see the Curated Courses Project.

## Related Cells

Any related cells go here. Provide a link to the page containing the information about the cell.