summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
cf491ed)
still need error handling...
</head>
<body>
<div id='container'>
</head>
<body>
<div id='container'>
-
- <h1>matrix.py</h1>
- Find the kernel, determinant and eigenvalues of a given matrix.
-
- <form>
+ <h1>matrix.py</h1>
+ <div id='description'>
+ Find the kernel, determinant and eigenvalues of a given matrix.
+ </div>
+ <form>
<textarea id="matrix">2 3 5
-4 2 3
0 0 0</textarea></br>
<a id='submit' href='#'>./calculate</a>
<textarea id="matrix">2 3 5
-4 2 3
0 0 0</textarea></br>
<a id='submit' href='#'>./calculate</a>
- </form>
-
- <ul id='results'></ul>
-
- <div id='clear'></div>
-
- <div id="footer">
- <h2><a href="http://dylansserver.com">dylansserver.com</a>
+ </form>
+ <ul id='results'></ul>
+ <div id='clear'></div>
+ <div id="footer">
+ <h2><a href="http://dylansserver.com">dylansserver.com</a>
+ </div>
- $.post('/calculate', { 'matrix' : $('#matrix').val() })
+ $.get('/calculate', { 'matrix' : $('#matrix').val() })
.done(function(data) {
$('#results').fadeOut('slow', function() {
$('#results').html('').append(
.done(function(data) {
$('#results').fadeOut('slow', function() {
$('#results').html('').append(
+import cgi
+from scipy import compress, transpose
+from scipy.linalg import svd, det
-import scipy
-import scipy.linalg
-from scipy import *
-
-def null(A, eps=1e-15):
- u, s, vh = scipy.linalg.svd(A)
+def calculate_nullspace(A, eps=1e-15):
+ u, s, vh = svd(A)
- null_space = scipy.compress(null_mask, vh, axis=0)
- return scipy.transpose(null_space)
+ null_space = compress(null_mask, vh, axis=0)
+ return transpose(null_space)
-def eigenvalues(A, eps=1e-15):
- u, s, vh = scipy.linalg.svd(A)
+def calculate_eigenvalues(A, eps=1e-15):
+ u, s, vh = svd(A)
return s
def application(environ, start_response):
return s
def application(environ, start_response):
- if environ['REQUEST_METHOD'] == 'POST':
- post_data = environ['wsgi.input'].read()
+ parameters = cgi.parse_qs(environ.get('QUERY_STRING', ''))
- post_data = urlparse.parse_qsl(post_data, True, True)
+ query_string = str(parameters['matrix'][0])
+ matrix = query_string.splitlines()
+ for index, row in enumerate(matrix):
+ matrix[index] = row.split()
- data_string = str(post_data[0][1])
- data_rows = data_string.splitlines()
- for index, row in enumerate(data_rows):
- data_rows[index] = row.split()
+ while len(matrix) < len(matrix[0]):
+ matrix.append([0]*len(matrix[0]))
- given_matrix = data_rows
- null_space = null(given_matrix)
- try:
- null_space = null_space / null_space.max()
- except:
- pass
+ nullspace = calculate_nullspace(matrix)
+ if nullspace.max() != 0:
+ nullspace = nullspace / nullspace.max()
-# la, v = scipy.linalg.eig(given_matrix)
-# output += "eigenvalues:<br>"
-# for l in la:
-# output += str(l)
- determinant = scipy.linalg.det(given_matrix)
+ eigenvalues = calculate_eigenvalues(matrix)
+ determinant = det(matrix)
- 'nullspace' : str(null_space),
- 'eigenvalues' : str(eigenvalues(given_matrix)),
+ 'nullspace' : str(nullspace),
+ 'eigenvalues' : str(eigenvalues),
'determinant' : str(determinant)
})
'determinant' : str(determinant)
})
+#description {
+ margin-bottom: 30px;
+}
+