]> git.rustad.me Git - nummat1/commitdiff
Fix int division error in functions
authorBjørn Rustad <rustadbjornen@gmail.com>
Thu, 29 Sep 2011 08:57:27 +0000 (10:57 +0200)
committerBjørn Rustad <rustadbjornen@gmail.com>
Thu, 29 Sep 2011 08:57:27 +0000 (10:57 +0200)
function.py
surf.py

index 6a4dafed3ccb0ec23bacef43ebf73ec330ab12d9..480ceb9d03104a5e959e170c02ea10d0b7fbffd7 100644 (file)
@@ -2,7 +2,7 @@ import numpy as np
 
 # Calculate function value in point x
 def function_g(x, H, b, c):
-    return -b.T.dot(x) + 0.5 * x.T.dot(H.dot(x)) + (1/12) * x.T.dot(_C(x,c).dot(x))
+    return -b.T.dot(x) + 0.5 * x.T.dot(H.dot(x)) + (1.0/12.0) * x.T.dot(_C(x,c).dot(x))
 
 # Create matrix C(x)
 def _C(x, c):
@@ -13,7 +13,7 @@ def _C(x, c):
 
 # Calculate gradient of g in point x
 def gradient_g(x, H, b, c):
-    return -b.T + 0.5 * H.dot(x) + 0.5 * H.T.dot(x) + (1/3) * x.T.dot(_C(x,c))
+    return -b.T + 0.5 * H.dot(x) + 0.5 * H.T.dot(x) + (1.0/3.0) * x.T.dot(_C(x,c))
 
 # Calculate hessian of g in point x
 def hessian_g(x, H, b, c):
diff --git a/surf.py b/surf.py
index 27ccde9362aeb6e6ddc2eb99b303f94d27af475e..1c1f2f4a31277841ebf42933d771f6e2daee693c 100644 (file)
--- a/surf.py
+++ b/surf.py
@@ -13,6 +13,6 @@ def surf(H, b, c, xmin, xmax, ymin, ymax, zmin, zmax):
     for i in xrange(dim):
         for j in xrange(dim):
             Z[i][j] = function.function_g(np.array([X[i][j],Y[i][j]]), H, b, c)
-            if Z[i][j] > zmax:
-                Z[i][j] = NaN
+#            if Z[i][j] > zmax:
+#                Z[i][j] = NaN
     return X, Y, Z