Design of classes for dynamical systems
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 https://github.com/worden-lee/SageDyn..., and there's some more stuff in other files there. Example output is at http://lalashan.mcmaster.ca/theobio/w....
Questions:
- 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
Yep, that's probably a good question for sage-devel !