示例#1
0
 def computeError(self):
     """Computes absolute error using an L2 norm for the solution.
     This requires that self.u and self.old_u must be appropriately
     setup."""
     # use flat
     v = (self.u - self.old_u).flat
     return numpy.sqrt(numpy.dot(v, v))
示例#2
0
 def computeError(self):        
     """Computes absolute error using an L2 norm for the solution.
     This requires that self.u and self.old_u must be appropriately
     setup."""        
     # use flat
     v = (self.u - self.old_u).flat
     return numpy.sqrt(numpy.dot(v,v))
示例#3
0
#np.ufunc_random(Vy,Vy)
Vy  = np.random.random_sample((n,1))
#Vz = np.empty((n,1))
#np.ufunc_random(Vz,Vz)
Vz  = np.random.random_sample((n,1))

OnesCol = np.zeros((n,1), dtype=float)+1.0
OnesRow = np.zeros((1,n), dtype=float)+1.0
#Identity= array(diag([1]*n), dtype=double)

#np.timer_reset()
#np.evalflush()
stime = time.time()
for i in xrange(k):
    #distance between all pairs of objects
    Fx = np.dot(OnesCol, PxT) - np.dot(Px, OnesRow)
    Fy = np.dot(OnesCol, PyT) - np.dot(Py, OnesRow)
    Fz = np.dot(OnesCol, PzT) - np.dot(Pz, OnesRow)

    Dsq = Fx * Fx
    Dsq += Fy * Fy
    Dsq += Fz * Fz
    #Dsq += Identity
    D = np.sqrt(Dsq)

    #mutual forces between all pairs of objects
    F = np.dot(M, MT)
    F *= G
    F /= Dsq
    del Dsq
    #F = F - diag(diag(F))#set 'self attraction' to 0