示例#1
0
    def check_lu(self):
        a = random((10,10))
        b = random((10,))

        x1 = solve(a,b)

        lu_a = lu_factor(a)
        x2 = lu_solve(lu_a,b)

        assert_array_equal(x1,x2)
 def __iter__(self):
     f = self.f
     x0 = self.x0
     norm = self.norm
     J = self.J
     fx = matrix(f(*x0))
     fxnorm = norm(fx)
     cancel = False
     while not cancel:
         # get direction of descent
         fxn = -fx
         Jx = J(*x0)
         s = lu_solve(Jx, fxn)
         if self.verbose:
             print 'Jx:'
             print Jx
             print 's:', s
         # damping step size TODO: better strategy (hard task)
         l = one
         x1 = x0 + s
         while True:
             if x1 == x0:
                 if self.verbose:
                     print "canceled, won't get more excact"
                 cancel = True
                 break
             fx = matrix(f(*x1))
             newnorm = norm(fx)
             if newnorm < fxnorm:
                 # new x accepted
                 fxnorm = newnorm
                 x0 = x1
                 break
             l /= 2
             x1 = x0 + l * s
         yield (x0, fxnorm)
示例#3
0
 def __iter__(self):
     f = self.f
     x0 = self.x0
     norm = self.norm
     J = self.J
     fx = matrix(f(*x0))
     fxnorm = norm(fx)
     cancel = False
     while not cancel:
         # get direction of descent
         fxn = -fx
         Jx = J(*x0)
         s = lu_solve(Jx, fxn)
         if self.verbose:
             print 'Jx:'
             print Jx
             print 's:', s
         # damping step size TODO: better strategy (hard task)
         l = one
         x1 = x0 + s
         while True:
             if x1 == x0:
                 if self.verbose:
                     print "canceled, won't get more excact"
                 cancel = True
                 break
             fx = matrix(f(*x1))
             newnorm = norm(fx)
             if newnorm < fxnorm:
                 # new x accepted
                 fxnorm = newnorm
                 x0 = x1
                 break
             l /= 2
             x1 = x0 + l*s
         yield (x0, fxnorm)