-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.html
105 lines (91 loc) · 4.35 KB
/
index.html
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<html>
<head>
<link rel="stylesheet" href="CodeMirror/lib/codemirror.css">
<link rel="stylesheet" href="stylesheet.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js" type="text/javascript"></script>
<!-- skulpt for python to js -->
<script src="skulpt.min.js" type="text/javascript"></script>
<script src="skulpt-stdlib.js" type="text/javascript"></script>
<!-- codemirror for a syntax highlighting in the editor -->
<script src="CodeMirror/lib/codemirror.js"></script>
<script src="CodeMirror/mode/python/python.js"></script>
</head>
<body>
<section>
<div id="left">
<h2>Routh-Hurwitz Criterion Calculator</h2>
<h3>Input</h3>
<textarea id="input">
#this is editable python code!
coefficients = [1,3,2,0,0]
significant_figures = 4
approximate_mode = True</textarea>
<h3>Output</h3>
<pre id="output"></pre>
<h3>Instructions</h3>
<p>Enter coefficients in descending order of s, specify the significant figures, and specify with which mode to do the calculations.</p>
<p>As you modify the input code, the output will be continuously updated.</p>
<h3>Approximate Mode</h3>
<p> This program approximates
<sup>±1</sup>⁄
<sub>0</sub>= ±10
<sup>100</sup>,
<sup>0</sup>⁄
<sub>0</sub>= 1, and 0 = 10
<sup>−100</sup>. To see why approximate mode is important, compare modes <code>True</code> and <code>False</code> with the program's default coefficients of <code>[1,3,2,0,0]</code>.
</p>
<h3>About</h3>
<p>This program uses <a href="http://www.skulpt.org/">Skulpt</a> and <a href="http://codemirror.net/index.html">CodeMirror</a>. Skulpt is a pretty cool in-browser Python interpretter, so feel free to play around with the input and try to crash your browser. Unfortunately Python's' <code>eval</code> function has not been implemented yet, so this application only does numerical Routh-Hurwitz calculations.</p>
<p><a href="https://github.com/crclayton/routh-hurwitz-calc">Fork me on GitHub</a></p>
</div>
<div id="right">
<div id="adspace" style="background-color: black">
<ins class="adsbygoogle" style="display:inline-block;width:300px;height:600px" data-ad-client="ca-pub-5056860500942857"
data-ad-slot="4470162525"></ins>
</div>
</div>
</section>
<textarea id="python_code">
coefficients = [float(i) for i in coefficients]
n = len(coefficients) - 1
r = []
# this program will do the routh-hurwitz of any
# order polynomial if you add more padding.
# We give enough for order 40 which should
padding = [0]*20
# show the user the polynomial
s = [str(a) + "s<sup>" + str(i) + "</sup>" for i, a in enumerate(coefficients[::-1])]
print "characteristic equation: \n " + " + ".join(s[::-1]) + "\n"
# create the top two rows
r.append(coefficients[::2] + padding)
r.append(coefficients[1::2] + padding)
# implement the algorithm here: http://en.wikipedia.org/wiki/Routh%E2%80%93Hurwitz_stability_criterion#Higher-order_example
for j in range(2, len(coefficients)):
row = []
for i in range(n):
numerator = (r[j-1][0]*r[j-2][i+1])-(r[j-2][0]*r[j-1][i+1])
denominator = r[j-1][0]
if denominator == 0:
if numerator > 0: result = 10**100
elif numerator < 0: result = -(10**100)
else: result = 1
else:
result = numerator/denominator
if result == 0 and approximate_mode == True:
result = 10**(-100)
row.append(result)
r.append(row + padding)
# print the created routh-hurwitz table
table = "<table>"
for row in r:
table += "<tr>"
for i in range(n):
result = "%s" % float( ("%." + str(significant_figures) + "g") % row[i])
if i == 0: result = "<b>" + result + "</b>"
table += "<td>" + result + "</td>"
table += "</tr>"
print table + "</table>"
</textarea>
</body>
<script src="code.js" type="text/javascript"></script>
</html>