-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpm.py
33 lines (30 loc) · 851 Bytes
/
expm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from numpy import zeros, ones, array, empty
from expokit import dgpadm
def makef(nstates, ideg=4):
"""
make a function for exponentiating a nstates-by-nstates transition
matrix
"""
ncells = nstates*nstates
lwsp = 4*ncells + ideg + 1
ipiv = zeros(nstates, dtype=int)
wsp = empty(lwsp)
def f(Q, t, ipiv=ipiv, wsp=wsp):
x = dgpadm(ideg, t, Q, wsp, ipiv)
print x
i = x[0]-1
print nstates, i
p = wsp[i:i+ncells].reshape((nstates,nstates))
return p.T
return f
for i in range(2, 20):
q = ones((i,i), dtype=float)
f = makef(i)
f(q, 1)
## q = array([[-1, 1, 0, 0, 0],
## [ 0, -1, 1, 0, 0],
## [ 0, 0, -1, 1, 0],
## [ 0, 0, 0, -1, 1],
## [ 0, 0, 1, 0, -1]], dtype=float)
## f = makef(5)
## f(q, 1)