sdeint icon indicating copy to clipboard operation
sdeint copied to clipboard

allow arguments to f and G functions

Open sdx23 opened this issue 9 years ago • 5 comments

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

sdx23 avatar Dec 11 '16 20:12 sdx23

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.

mattja avatar Dec 13 '16 12:12 mattja

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

HuwLittle avatar Dec 19 '17 11:12 HuwLittle

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.

mattja avatar Dec 19 '17 23:12 mattja

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

LorenzoBottaccioli avatar Jul 01 '19 13:07 LorenzoBottaccioli

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)

mattja avatar Jul 02 '19 00:07 mattja