Reputation: 21049
In NumPy, I'm trying to represent differential equations of the form: y' = p(t)y + g(t)
, where p(t)
is an nxn matrix and and g(t)
is an nx1 matrix. Something like:
y' = [[1,5], [2,1]] + [[e^t], [1]]
I know how to represent matrices in NumPy, but how would I represent matrices that contain variables (for example, 2t
or e^t
)?
Upvotes: 2
Views: 8399
Reputation: 46568
A 'variable' in this sense (as in, y
is a function of t
) should probably be represented by a 1d array of that variable's domain. This would increase the dimension of your array (making it (n, n, m)
where m
is the size of your domain (length of t
).
If you plan on using a scipy ode solver, then you write it as a function, so instead of
t = np.arange(0, 10, .1)
y' = [[1,5]*len(t), [2,1]*len(t)] + [[np.exp(t)], [1]*len(t)]
you need to do something like:
def yderiv(t):
return [[1,5], [2,1]] + [[np.exp(t)], [1]]
Upvotes: 1