Reputation: 83
The odeintw example we get something like this:
def asys(a, t, c):
return c.dot(a)
c = np.array([[-0.5, -1.25],
[ 0.5, -0.25]])
t = np.linspace(0, 10, 201)
# a0 is the initial condition.
a0 = np.array([[0.0, 2.0],
[2.0, 3.0]])
# Call `odeintw`.
sol = odeintw(asys, a0, t, args=(c,))
But I wanna know if it is possible to solve a problem for a c
that is time dependent. For it written like (example):
c = np.random.rand(201,2,2)
I would like to write a function that odeintw understand for each t
one correspondent c
. Can someone help me?
Upvotes: 0
Views: 174
Reputation: 26040
The principal point to notice is that the ODE solver will evaluate the function asys
at arbitrary values of t
. Thus you will need to interpolate the function table for c
. You would have to check if the existing interpolation functions can handle multi-dimensional arrays. Probably you will need a work-around or wrapper just like odeintw
provides for odeint
.
This will work very poorly, if at all, for the presented test example. A random array will give a very jumpy function table, while the ODE solver rely on the differential equation being smooth. Non-smooth behavior leads to very small step sizes and thus very many function evaluations.
Upvotes: 1