[SciPy-user] ode/programming question
Mon Apr 30 12:48:04 CDT 2007
On 30/04/07, Trevis Crane <firstname.lastname@example.org> wrote:
> When using one of the ODE solvers, you can pass it a list of arguments.
> These arguments are used in the function that defines the system of linear
> equations that you're solving. What if I want to modify an argument every
> iteration and re-pass this modified argument to the helper function in the
> next iteration? In Matlab (what I'm most familiar with), this is easy to do,
> using "nested" functions, because they share the same scope/namespace as the
> function they're nested in. This is not the case in Python, however, so I'm
> curious what the best way of doing this would be. I assume I define a
> global variable, but I'm wondering if there's another, perhaps better, way
> of doing it.
I would use a class that implements the __callable__ method if I
wanted to store some state. But be warned that the ODE solver is going
to assume that your function always returns the same value for the
same inputs, and it's unlikely to call the function in t order.
Incidentally, I've never understood why python has all those "args"
arguments. It makes the code and signature for functions with function
arguments complicated and confusing, and it's not usually enough: for
example, if you want to use the minimization functions to maximize,
you either have to write a function apurpose or you have to feed it a
lambda; in either case you can easily curry the function arbitrarily.
So I never ever use the "args" arguments. Why are they there?
More information about the SciPy-user