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


Python polyroots.roots_linear函数代码示例

本文整理汇总了Python中sympy.polys.polyroots.roots_linear函数的典型用法代码示例。如果您正苦于以下问题:Python roots_linear函数的具体用法?Python roots_linear怎么用?Python roots_linear使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: __new__

    def __new__(cls, expr, func=None, x=None, auto=True, quadratic=False):
        """Construct a new ``RootSum`` instance carrying all roots of a polynomial. """
        coeff, poly = cls._transform(expr, x)

        if not poly.is_univariate:
            raise MultivariatePolynomialError("only univariate polynomials are allowed")

        if func is None:
            func = Lambda(poly.gen, poly.gen)
        else:
            try:
                is_func = func.is_Function
            except AttributeError:
                is_func = False

            if is_func and (func.nargs == 1 or 1 in func.nargs):
                if not isinstance(func, Lambda):
                    func = Lambda(poly.gen, func(poly.gen))
            else:
                raise ValueError("expected a univariate function, got %s" % func)

        var, expr = func.args

        if coeff is not S.One:
            expr = expr.subs(var, coeff*var)

        deg = poly.degree()

        if not expr.has(var):
            return deg*expr

        if expr.is_Add:
            add_const, expr = expr.as_independent(var)
        else:
            add_const = S.Zero

        if expr.is_Mul:
            mul_const, expr = expr.as_independent(var)
        else:
            mul_const = S.One

        func = Lambda(var, expr)

        rational = cls._is_func_rational(poly, func)
        (_, factors), terms = poly.factor_list(), []

        for poly, k in factors:
            if poly.is_linear:
                term = func(roots_linear(poly)[0])
            elif quadratic and poly.is_quadratic:
                term = sum(map(func, roots_quadratic(poly)))
            else:
                if not rational or not auto:
                    term = cls._new(poly, func, auto)
                else:
                    term = cls._rational_case(poly, func)

            terms.append(k*term)

        return mul_const*Add(*terms) + deg*add_const
开发者ID:haz,项目名称:sympy,代码行数:60,代码来源:rootoftools.py

示例2: _roots_trivial

    def _roots_trivial(cls, poly, radicals):
        """Compute roots in linear, quadratic and binomial cases. """
        if poly.degree() == 1:
            return roots_linear(poly)

        if not radicals:
            return None

        if poly.degree() == 2:
            return roots_quadratic(poly)
        elif poly.length() == 2 and poly.TC():
            return roots_binomial(poly)
        else:
            return None
开发者ID:A-turing-machine,项目名称:sympy,代码行数:14,代码来源:rootoftools.py

示例3: roots_trivial

def roots_trivial(poly, radicals=True):
    """Compute roots in linear, quadratic and binomial cases. """
    if poly.degree() == 1:
        return roots_linear(poly)
    else:
        if not radicals:
            return None

        if poly in _rootof_trivial_cache:
            roots = _rootof_trivial_cache[poly]
        else:
            if radicals and poly.degree() == 2:
                roots = roots_quadratic(poly)
            elif radicals and poly.length() == 2 and poly.TC():
                roots = roots_binomial(poly)
            else:
                return None

            _rootof_trivial_cache[poly] = roots

        return roots
开发者ID:haz,项目名称:sympy,代码行数:21,代码来源:rootoftools.py

示例4: _roots_trivial

    def _roots_trivial(cls, poly, radicals):
        """Compute roots in linear, quadratic and binomial cases. """
        if poly.degree() == 1:
            return roots_linear(poly)

        if not radicals:
            return None
        free = len(poly.free_symbols)
        sort = isinstance(poly, PurePoly) and free or free > 1
        if poly.degree() == 2:
            roots = roots_quadratic(poly, sort=sort)
        elif poly.length() == 2 and poly.TC():
            roots = roots_binomial(poly, sort=sort)
        else:
            return None
        # put roots in same order as RootOf instances
        if not sort:
            key = [r.n(2) for r in roots]
            key = [(1 if not r.is_real else 0, C.re(r), C.im(r))
                for r in key]
            _, roots = zip(*sorted(zip(key, roots)))
        return roots
开发者ID:MCGallaspy,项目名称:sympy,代码行数:22,代码来源:rootoftools.py

示例5: test_roots_linear

def test_roots_linear():
    assert roots_linear(Poly(2*x + 1, x)) == [-Rational(1, 2)]
开发者ID:NalinG,项目名称:sympy,代码行数:2,代码来源:test_polyroots.py


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