Description
We can compute a numerical solution for a system of first-order ordinary differential equations using odeint from scipy.integrate module. The following Sage commands can be used to find a numerical solution to the Lotka-Volterra predator-prey equations:
(1)where $0 \leq t \leq 10$ with a step size of $h = 0.1$. odeint implements LSODA, and it automatically selects between nonstiff (Adams) and stiff (BDF) methods. It uses the nonstiff method initially, and dynamically monitors data in order to decide which method to use. More information about the scipy.integrate module can be found at https://docs.scipy.org/doc/scipy/reference/integrate.html#module-scipy.integrate.
Sage Cell
Code
x,y=var('x,y')
f=[x*(1-y),-y*(1-x)]
sol=desolve_odeint(f,[0.5,2],srange(0,10,0.1),[x,y])
p=line(zip(sol[:,0],sol[:,1]))
p.show()
Options
None
Tags
Primary Tags: Differential Equations
Secondary Tags: Numerical Methods: Systems
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
- desolve. Solving ordinary differential equations with desolve.
- Euler's Method. eulers_method implements Euler’s method for finding a numerical solution of the first-order ODE $y′=f(x,y)$.
- Euler's Method for Systems. eulers_method_2x2 implements Euler’s method for finding a numerical solution of a $2 \times 2$ system of first-order ODEs.
- desolve_laplace. Solving ordinary differential equations using Laplace transforms.
- Interact to plot direction fields and solutions for first order differential equations. A Sage interact for plotting direction fields for differential equations.
Attribute
Permalink:
Author: Sage Tutorial v8.1 and https://docs.scipy.org/doc/scipy/reference/integrate.html#module-scipy.integrate
Date: 14 Feb 2018 15:21
Submitted by: Tom Judson