当前位置: 首页>>代码示例>>Python>>正文


Python Matrix.det方法代码示例

本文整理汇总了Python中sympy.matrices.Matrix.det方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.det方法的具体用法?Python Matrix.det怎么用?Python Matrix.det使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sympy.matrices.Matrix的用法示例。


在下文中一共展示了Matrix.det方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: sylvester_det

# 需要导入模块: from sympy.matrices import Matrix [as 别名]
# 或者: from sympy.matrices.Matrix import det [as 别名]
def sylvester_det(p4, p2):
    p4degree = len(p4) - 1
    p2degree = len(p2) - 1
    smatsize = p4degree + p2degree
    nzeros4 = (smatsize - len(p4))
    nzeroes2 = (smatsize - len(p2))
    smatlist = []
    for i in range(nzeros4 + 1):
        smatlist.append([0]*i + p4 + [0]*(nzeros4 - i))
    for i in range(nzeroes2 + 1):
        smatlist.append([0]*i + p2 + [0]*(nzeroes2 - i))

    smat = Matrix(smatlist)
    det = smat.det(method='berkowitz')
    det = sympy.expand(det)
    return det
开发者ID:iEarthos,项目名称:mutual_localization,代码行数:18,代码来源:scalefactors.py

示例2: find_linear_recurrence

# 需要导入模块: from sympy.matrices import Matrix [as 别名]
# 或者: from sympy.matrices.Matrix import det [as 别名]
    def find_linear_recurrence(self,n,d=None,gfvar=None):
        """
        Finds the shortest linear recurrence that satisfies the first n
        terms of sequence of order `\leq` n/2 if possible.
        If d is specified, find shortest linear recurrence of order
        `\leq` min(d, n/2) if possible.
        Returns list of coefficients ``[b(1), b(2), ...]`` corresponding to the
        recurrence relation ``x(n) = b(1)*x(n-1) + b(2)*x(n-2) + ...``
        Returns ``[]`` if no recurrence is found.
        If gfvar is specified, also returns ordinary generating function as a
        function of gfvar.

        Examples
        ========

        >>> from sympy import sequence, sqrt, oo, lucas
        >>> from sympy.abc import n, x, y
        >>> sequence(n**2).find_linear_recurrence(10, 2)
        []
        >>> sequence(n**2).find_linear_recurrence(10)
        [3, -3, 1]
        >>> sequence(2**n).find_linear_recurrence(10)
        [2]
        >>> sequence(23*n**4+91*n**2).find_linear_recurrence(10)
        [5, -10, 10, -5, 1]
        >>> sequence(sqrt(5)*(((1 + sqrt(5))/2)**n - (-(1 + sqrt(5))/2)**(-n))/5).find_linear_recurrence(10)
        [1, 1]
        >>> sequence(x+y*(-2)**(-n), (n, 0, oo)).find_linear_recurrence(30)
        [1/2, 1/2]
        >>> sequence(3*5**n + 12).find_linear_recurrence(20,gfvar=x)
        ([6, -5], 3*(-21*x + 5)/((x - 1)*(5*x - 1)))
        >>> sequence(lucas(n)).find_linear_recurrence(15,gfvar=x)
        ([1, 1], (x - 2)/(x**2 + x - 1))
        """
        from sympy.matrices import Matrix
        x = [simplify(expand(t)) for t in self[:n]]
        lx = len(x)
        if d == None:
            r = lx//2
        else:
            r = min(d,lx//2)
        coeffs = []
        for l in range(1, r+1):
            l2 = 2*l
            mlist = []
            for k in range(l):
                mlist.append(x[k:k+l])
            m = Matrix(mlist)
            if m.det() != 0:
                y = simplify(m.LUsolve(Matrix(x[l:l2])))
                if lx == l2:
                    coeffs = flatten(y[::-1])
                    break
                mlist = []
                for k in range(l,lx-l):
                    mlist.append(x[k:k+l])
                m = Matrix(mlist)
                if m*y == Matrix(x[l2:]):
                    coeffs = flatten(y[::-1])
                    break
        if gfvar == None:
            return coeffs
        else:
            l = len(coeffs)
            if l == 0:
                return [], None
            else:
                n, d = x[l-1]*gfvar**(l-1), 1 - coeffs[l-1]*gfvar**l
                for i in range(l-1):
                    n += x[i]*gfvar**i
                    for j in range(l-i-1):
                        n -= coeffs[i]*x[j]*gfvar**(i+j+1)
                    d -= coeffs[i]*gfvar**(i+1)
                return coeffs, simplify(factor(n)/factor(d))
开发者ID:chaffra,项目名称:sympy,代码行数:76,代码来源:sequences.py

示例3: Context

# 需要导入模块: from sympy.matrices import Matrix [as 别名]
# 或者: from sympy.matrices.Matrix import det [as 别名]
class Context(object):
	"""some context where variables exists"""
	def __init__(self, size):
		self.numberOfVariables = size
		self.x = s.symbols('x:'+str(size))
		self.fn = None
		self.hessian = None
		self.detHessian = None

	def setFn(self, expression):
		self.fn = expression

	def getHessian(self):

		expr = self.fn

		hessianRows = []
		for idx in range(0, self.numberOfVariables):

			hessianRow = []

			diffWrt = s.diff(expr, self.x[idx])

			for idx2ndDeriv in range(0, self.numberOfVariables):

				hessianRow.append(s.diff(diffWrt, self.x[idx2ndDeriv]))

			hessianRows.append(hessianRow)

		self.hessian = Matrix(hessianRows)

		return self.hessian

	# compute the determinate of the hessian at point [x1 .. xn]
	def detHessianAt(self, subs):

		if len(subs) != self.numberOfVariables:

			raise Exception('airity mismatch: detHessianAt')

		if self.hessian == None:

			self.hessian = self.getHessian()

		if self.detHessian == None:

			self.detHessian = self.hessian.det()

		detHessian = self.detHessian

		for idx in range(0, self.numberOfVariables):

			detHessian = detHessian.subs(self.x[idx], subs[idx]);

		return detHessian


	def secondPartialTest(self, subs):

		dValue = self.detHessianAt(subs).evalf()

		if(dValue < 0):

			return "Saddle Point at f(" + str(subs) + ")"

		if(dValue == 0):

			return "Inconclusive at f(" + str(subs) + ")"

		# get the function at the top left of the hession
		secondDerivAtSub = self.hessian[0,0]

		value = secondDerivAtSub

		for idx in range(0, self.numberOfVariables):

			value = value.subs(self.x[idx], subs[idx]);

		value = value.evalf()

		if value > 0:

			return "Relative Minimum at f(" + str(subs) + ")"

		if value < 0:

			return "Relative Maximum at f(" + str(subs) + ")"
开发者ID:DiNAi,项目名称:WscuCalcIII,代码行数:89,代码来源:hessian.py


注:本文中的sympy.matrices.Matrix.det方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。