Interact to Plot Phase Planes of Systems of Differential Equations
Description
A Sage interact Interact that plots phase planes of systems of Differential Equations with nullclines. The default plot is
(1)\begin{align} x' & = x(1 - x) - 2xy \\ y' & = y(1-y) - 2xy. \end{align}
There is an option to include $x$ and $y$-nullclines.
Sage Cell
Code
x,y,t = var('x,y,t')
@interact
def _(f = input_box(default = "x*(1 - x) - 2*x*y"),
g = input_box(default = "y*(1-y) - 2*x*y"),
x_min = input_box(default = 0), x_max = input_box(default = 1.5),
y_min = input_box(default = 0), y_max = input_box(default = 1.5),
t_start = input_box(default = 0.0), x_start = input_box(default = 1.4), y_start = input_box(default = 1.3),
step_size = (0.01, (0.001, 1.0)), t_end = (10, (5, 50)),
x_null = checkbox(False, "Show $x$-nullcline (green)"),
y_null = checkbox(False, "Show $y$-nullcline (red)")):
n = sqrt(f^2 + g^2)
p = plot_vector_field( (f/n, g/n), (x, x_min, x_max), (y, y_min, y_max))
p += point((x_start, y_start), pointsize=50)
P = desolve_system_rk4([f, g], [x, y],ics = [t_start, x_start, y_start], ivar = t, end_points = t_end, step = step_size)
Q = [ [j,k] for i,j,k in P]
p += line(Q, axes_labels = ['$x(t)$','$y(t)$'])
p += arrow(Q[int(len(Q)) - 2], Q[int(len(Q)) - 1], width = 1, arrowsize = 4)
x_nullcline = implicit_plot(f, (x, x_min, x_max), (y, y_min, y_max), color = 'green', legend_label = '$x$-nullcline')
y_nullcline = implicit_plot(g, (x, x_min, x_max), (y, y_min, y_max), color = 'red', legend_label = '$y$-nullcline')
if x_null:
p += x_nullcline
if y_null:
p += y_nullcline
p.show(xmin = x_min, xmax = x_max, ymin = y_min, ymax = y_max, aspect_ratio = 1)
pretty_print(html("<br />"))
pretty_print(html(r"$\displaystyle\frac{dx}{dt} = %s$" %latex(f)))
pretty_print(html("<br />"))
pretty_print(html(r"$\displaystyle\frac{dy}{dt} = %s$" %latex(g)))
Options
None.
Tags
Primary Tags—Differential equations: Systems of differential equations; Programming: Python
Secondary Tags—Systems of differential equations: Phase planes; Python: Interacts
Related Cells
- desolve_system. Solving a system of ordinary differential equations with desolve_system.
- Euler's Method for Systems. eulers_method_2x2 implements Euler’s method for finding a numerical solution of a
- Plotting Direction Fields for Differential Equations. Plotting direction fields and solutions for first-order differential equations.
- Interact to plot direction fields and solutions for first order differential equations. A Sage interact for plotting direction fields for differential equations.
- Interact to Plot Phase Planes of Systems of Differential Equations. A Sage interact Interact that plots phase planes of systems of Differential Equations with nullclines.
Attribute
Permalink:
Author: T. W. Judson
Date: 21 Dec 2019 15:21
Submitted by: Tom Judson