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)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[0]^2 + vec[1]^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
Adding a Solution Curve
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[0].rhs(), sols[1].rhs()])
var('x y')
vec = vector([x + 3*y, x - y])
mag = sqrt(vec[0]^2 + vec[1]^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[0].rhs(), sols[1].rhs()])
var('x y')
vec = vector([x + 3*y, x - y])
mag = sqrt(vec[0]^2 + vec[1]^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.
Attribute
Permalink:
Author: Thomas Judson
Date: 25 May 2020 23:10
Submitted by: Zane Corbiere