コード例 #1
0
ファイル: quadrature.py プロジェクト: gnulinooks/sympy
    def sum_next(self, f, nodes, degree, prec, previous, verbose=False):
        r"""
        Evaluates the step sum `\sum w_k f(x_k)` where the *nodes* list
        contains the `(w_k, x_k)` pairs.

        :func:`summation` will supply the list *results* of
        values computed by :func:`sum_next` at previous degrees, in
        case the quadrature rule is able to reuse them.
        """
        return fdot((w, f(x)) for (x,w) in nodes)
コード例 #2
0
    def sum_next(self, f, nodes, degree, prec, previous, verbose=False):
        r"""
        Evaluates the step sum `\sum w_k f(x_k)` where the *nodes* list
        contains the `(w_k, x_k)` pairs.

        :func:`summation` will supply the list *results* of
        values computed by :func:`sum_next` at previous degrees, in
        case the quadrature rule is able to reuse them.
        """
        return fdot((w, f(x)) for (x,w) in nodes)
コード例 #3
0
ファイル: quadrature.py プロジェクト: gnulinooks/sympy
 def sum_next(self, f, nodes, degree, prec, previous, verbose=False):
     """
     Step sum for tanh-sinh quadrature of degree `m`. We exploit the
     fact that half of the abscissas at degree `m` are precisely the
     abscissas from degree `m-1`. Thus reusing the result from
     the previous level allows a 2x speedup.
     """
     h = mpf(2)**(-degree)
     # Abscissas overlap, so reusing saves half of the time
     if previous:
         S = previous[-1]/(h*2)
     else:
         S = mpf(0)
     S += fdot((w,f(x)) for (x,w) in nodes)
     return h*S
コード例 #4
0
 def sum_next(self, f, nodes, degree, prec, previous, verbose=False):
     """
     Step sum for tanh-sinh quadrature of degree `m`. We exploit the
     fact that half of the abscissas at degree `m` are precisely the
     abscissas from degree `m-1`. Thus reusing the result from
     the previous level allows a 2x speedup.
     """
     h = mpf(2)**(-degree)
     # Abscissas overlap, so reusing saves half of the time
     if previous:
         S = previous[-1]/(h*2)
     else:
         S = mpf(0)
     S += fdot((w,f(x)) for (x,w) in nodes)
     return h*S
コード例 #5
0
 def __mul__(self, other):
     if isinstance(other, matrix):
         # dot multiplication  TODO: use Strassen's method?
         if self.__cols != other.__rows:
             raise ValueError('dimensions not compatible for multiplication')
         new = matrix(self.__rows, other.__cols)
         for i in xrange(self.__rows):
             for j in xrange(other.__cols):
                 new[i, j] = fdot((self[i,k], other[k,j])
                                  for k in xrange(other.__rows))
         return new
     else:
         # try scalar multiplication
         new = matrix(self.__rows, self.__cols)
         for i in xrange(self.__rows):
             for j in xrange(self.__cols):
                 new[i, j] = other * self[i, j]
         return new
コード例 #6
0
ファイル: matrices.py プロジェクト: gnulinooks/sympy
 def __mul__(self, other):
     if isinstance(other, matrix):
         # dot multiplication  TODO: use Strassen's method?
         if self.__cols != other.__rows:
             raise ValueError('dimensions not compatible for multiplication')
         new = matrix(self.__rows, other.__cols)
         for i in xrange(self.__rows):
             for j in xrange(other.__cols):
                 new[i, j] = fdot((self[i,k], other[k,j])
                                  for k in xrange(other.__rows))
         return new
     else:
         # try scalar multiplication
         new = matrix(self.__rows, self.__cols)
         for i in xrange(self.__rows):
             for j in xrange(self.__cols):
                 new[i, j] = other * self[i, j]
         return new