[SciPy-user] ode/programming question

Rob Clewley rhc28 at cornell.edu
Tue May 1 10:09:49 EDT 2007


On 01/05/07, Anne Archibald <peridot.faceted at gmail.com> wrote:
> On 30/04/07, Trevis Crane <t_crane at mrl.uiuc.edu> wrote:
>
> > I have a system of linear equations.  Each equation has the exact same form:
> >
> > phi_dot = Ij - Ic*sin(phi)
> >
> > Each of the equations has a different value for Ij, Ic, and phi, and indeed
> > their coupling is through these parameters.  Ij and Ic change dynamically
> > with in time subject to various constraints, including the way in which
> > they're coupled.  Whenever t changes, I have to recalculate several
> > parameters that are then used to determine Ij and Ic, but when the next time
> > step comes, I need to use the most recent values of Ij and Ic in order to
> > calculate the next values.  Furthermore, this evolution needs to continue
> > until the energy versus time of the system flattens out.  And the energy is
> > determined based upon these continually updating parameters.  Does this make
> > sense?  I have this simulation working in Matlab, but as I've mentioned I
> > want to try using Python in the future, so I thought I'd start with
> > something for which I already have a correct answer.
>
> That description - Ij and Ic need to be calculated based on previous
> values - is a bit vague. Is this a question of efficient computation,
> or one of definition? Are the Ij and Ic actually evolving according to
> a differential equation as well, perhaps?

It sounds like you might want to define auxiliary functions of your
variables and parameters that return the necessary values of lj and
lc. That is a much cleaner way to do what you're probably trying to
do. I expect you would have to pass in the names of these functions
explicitly as additional arguments (in the form Anne has described) in
order for your right-hand side function F to "see" the functions.

In order to stop a simulation when a certain condition has become true
you will need to use a more sophisticated integrator such as those
provided by PyDSTool or SloppyCell that allow user-defined events.
Also, those typically run significantly faster.

-Rob



More information about the SciPy-User mailing list