mattja / sdeint

Numerical integration of Ito or Stratonovich SDEs
GNU General Public License v3.0
155 stars 25 forks source link

allow arguments to f and G functions #8

Open sdx23 opened 7 years ago

sdx23 commented 7 years ago

odeint has args=[] for this purpose. In case of sdeint we'd possibly need two separate parameters, argsf and argsG.

mattja commented 7 years ago

Thanks, I think that is a useful suggestion, so that we can provide an interface as close to odeint as possible. I'll implement this when I can get some time. In the meantime you can get the same effect by passing a python closure in place of f or G.

HuwLittle commented 6 years ago

Hey there! Has any progress been made on this addition, would really appreciate it :)

mattja commented 6 years ago

In the current version, it is easy to achieve the same goal by using a function closure, so it is not a very high priority. A pull request adding this functionality would be welcome, of course.

LorenzoBottaccioli commented 5 years ago

@mattja can you provide an example using the function closure?

mattja commented 5 years ago
import numpy as np
import sdeint

def close(func, *args):
    def newfunc(x, t):
        return func(x, t, *args)
    return newfunc

tspan = np.linspace(0.0, 5.0, 5001)
x0 = 0.1

def f(x, t, a, b):
    return -(a + x*b**2)*(1 - x**2)

def g(x, t, a, b):
    return b*(1 - x**2)

args = (1.0, 0.8)
result = sdeint.itoint(close(f, *args), close(g, *args), x0, tspan)