Ask Your Question

Design of classes for dynamical systems

asked 2015-01-05 14:45:15 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

I have an ongoing project using Sage to process some dynamical systems (ODEs, that is), and along the way I've been developing some classes to generalize the process of storing an ODE system and working with it. I'd be interested in contributing the work to Sage if it's helpful, and in understanding what's a "sage-like" way to do it.

So here I'm wondering about what would be worth trying to contribute to Sage, and asking whether people would do the design differently.

I have a central class called ODEsystem, which is built around a dictionary encoding the flow function, e.g. if the system is

$$dx/dt = -ax-by$$ $$dy/dt = -cx-dy$$

the flow is a dictionary { x:-ax-by, y:-cx-dy } whose keys are variables and values are symbolic expressions. The object has methods to write itself out in LaTeX form, to integrate the dynamics from initial conditions, to find its equilibria and their stability, to make bifurcation diagrams under certain conditions, and a few other things. My intention is to allow room for a class hierarchy of models to develop, including difference equations, stochastic dynamics, PDEs, etc. There's also room to create subclasses and functions that derive specific models from general ones, simple models as limit cases of complex models, etc.

Another class that may be of use to others is Bindings, which binds variables to specific values in various expressions. For example, if I write

var('a, b')
generic_system = ODESystem( { x:a-bx }, vars=[x] )
specific_bindings = Bindings( a=1, b=2 )
latex( generic_system.bind( specific_bindings ) )

I'll get $dx/dt = 1-2x$. This is a wrapper for substitute() and substitute_function(), of course, but adds convenience and flexibility. (Note ODEsystem uses 'vars' to define the order of state variables. It's not logically necessary but it's useful in multiple dimensions.)

Code for those two classes is at, and there's some more stuff in other files there. Example output is at


  • Could something like this become a useful part of Sage
  • Would people want it to be designed differently
  • Different situations call for different choices of integration routines. One strategy is to provide different ODEsystem classes that use different numerical integrators, and another one is to uncouple the integration from the class that represents the system. I'm not sure what would be better.
  • Would it be good to represent the ODE as an element of a ring of vector fields on an appropriate manifold, with some extra methods added? It seems like that would provide some power, but I don't know the system well enough to go there right now.
  • Should I send this to sage-devel or something instead of posting here
edit retag flag offensive close merge delete


Yep, that's probably a good question for sage-devel !

Nathann gravatar imageNathann ( 2015-01-05 22:06:23 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2015-01-05 16:13:45 -0500

wonder gravatar image

I guess a Bindings is a morphism from SR to itself, that can be coerced more or less trivially to operate on vectors, vector fields, dynamical systems, etc. I don't know whether it would be useful to represent it that way somehow.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-01-05 14:45:15 -0500

Seen: 313 times

Last updated: Jan 05 '15