1 |
# This python script is called from roots.py to work around a crash in scipy |
2 |
# when called from an embedded python interpreter. |
3 |
|
4 |
import sys |
5 |
from scipy import io |
6 |
from scipy import linalg |
7 |
|
8 |
if len(sys.argv)<6: |
9 |
print "missing arguments" |
10 |
sys.exit(2) |
11 |
|
12 |
fff = { |
13 |
'dg/dz' : sys.argv[1] |
14 |
,'dg/dx' : sys.argv[2] |
15 |
,'df/dz' : sys.argv[3] |
16 |
,'df/dx' : sys.argv[4] |
17 |
,"df/dx'": sys.argv[5] |
18 |
} |
19 |
|
20 |
print "COMPUTING..." |
21 |
|
22 |
gz = io.mmread(fff['dg/dz']) |
23 |
gx = io.mmread(fff['dg/dz']) |
24 |
fz = io.mmread(fff['df/dz']) |
25 |
fx = io.mmread(fff['df/dx']) |
26 |
fxp =io.mmread(fff["df/dx'"]) |
27 |
|
28 |
print "gz", gz.shape |
29 |
print "gx", gx.shape |
30 |
print "fz", fz.shape |
31 |
print "fx", fx.shape |
32 |
print "fxp", fxp.shape |
33 |
|
34 |
if fxp.shape[0]==0: |
35 |
print "fxp is empty (0 rows)" |
36 |
sys.exit(1) |
37 |
|
38 |
if gz.shape[0]==0: |
39 |
if gx.shape[0]==0: |
40 |
sys.stderr.write("pure differential system\n") |
41 |
if fz.shape[1]!=0: |
42 |
print "pure differential system but with fz nonzero" |
43 |
sys.exit(2) |
44 |
|
45 |
invfxp = linalg.inv(fxp.todense()) |
46 |
D = - invfxp * fx |
47 |
else: |
48 |
print "gz is empty but gx is not!" |
49 |
sys.exit(1) |
50 |
|
51 |
else: |
52 |
#import pylab |
53 |
|
54 |
# dg/dy_a |
55 |
|
56 |
#pylab.spy2(ga.todense()) |
57 |
#pylab.title("${dg}/{dy_a}$") |
58 |
#pylab.show() |
59 |
|
60 |
invgz = linalg.inv(gz.todense()) |
61 |
|
62 |
#pylab.figure() |
63 |
#pylab.spy(invgz) |
64 |
#pylab.title("$({dg}/{dy_d})^{-1}$") |
65 |
#pylab.show() |
66 |
|
67 |
# dg/dy_d |
68 |
|
69 |
#pylab.figure() |
70 |
#pylab.spy2(gd.todense()) |
71 |
#pylab.title("${dg}/{dy_d}$") |
72 |
#pylab.show() |
73 |
|
74 |
# df/dyd' |
75 |
|
76 |
#pylab.figure() |
77 |
#pylab.spy2(fdp.todense()) |
78 |
#pylab.title("${df}/{d\dot{y}_d}$") |
79 |
#pylab.show() |
80 |
|
81 |
invfxp = linalg.inv(fxp.todense()) |
82 |
|
83 |
#pylab.spy2(invfdp) |
84 |
#pylab.title("$({df}/{dy_dp})^{-1}$") |
85 |
#pylab.show() |
86 |
|
87 |
dya_dyd = invgz * gx |
88 |
|
89 |
print "gz^-1 gx",dya_dyd.shape |
90 |
|
91 |
#pylab.spy2(dya_dyd.todense()) |
92 |
#pylab.title("${dy_a}/{dy_d}$") |
93 |
#pylab.show() |
94 |
|
95 |
B = fz * invgz * gx |
96 |
|
97 |
print "fz gz^1 gz",B.shape |
98 |
#pylab.spy2(fad.todense()) |
99 |
#pylab.title("${df}/{dy_a} * {dy_a}/{dy_d}$") |
100 |
#pylab.show() |
101 |
|
102 |
C = fx + B |
103 |
|
104 |
D = - invfxp * C |
105 |
|
106 |
e,v = linalg.eig(D.todense()) |
107 |
|
108 |
#print e |
109 |
|
110 |
print "max re(e)",max(e.real) |
111 |
print "min re(e)",min(e.real) |
112 |
print "max im(e)",max(e.imag) |
113 |
print "min im(e)",min(e.imag) |
114 |
|
115 |
import pylab, sys |
116 |
sys.stderr.write("about to plot...") |
117 |
pylab.plot(e.real,e.imag,'rx') |
118 |
pylab.title("Roots of dx'/dx for DAE system") |
119 |
pylab.xlabel("Real") |
120 |
pylab.ylabel("Imaginary") |
121 |
pylab.show() |
122 |
sys.stderr.write("DONE\n") |
123 |
|
124 |
sys.exit(0) |
125 |
|