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


Python sympy.Matrix方法代码示例

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


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

示例1: diff_inference

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Matrix [as 别名]
def diff_inference():
    
    r,s=symbols('r,s')
    
    la1,la2,lb1,lb2=symbols('l^a_1,l^a_2,l^b_1,l^b_2')
    
    la1=(1-s)/2
    la2=(1+s)/2
    lb1=(1-r)/2
    lb2=(1+r)/2
    N1=la1*lb1
    N2=la1*lb2
    N3=la2*lb1
    N4=la2*lb2
    
    N=Matrix([[N1,0,N2,0,N3,0,N4,0],
              [0,N1,0,N2,0,N3,0,N4]]) 
开发者ID:zhuoju36,项目名称:StructEngPy,代码行数:19,代码来源:test.py

示例2: get_equations

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Matrix [as 别名]
def get_equations(self):
        """
        :return: Functions to calculate A, B and f given state x and input u
        """
        f = sp.zeros(3, 1)

        x = sp.Matrix(sp.symbols('x y theta', real=True))
        u = sp.Matrix(sp.symbols('v w', real=True))

        f[0, 0] = u[0, 0] * sp.cos(x[2, 0])
        f[1, 0] = u[0, 0] * sp.sin(x[2, 0])
        f[2, 0] = u[1, 0]

        f = sp.simplify(f)
        A = sp.simplify(f.jacobian(x))
        B = sp.simplify(f.jacobian(u))

        f_func = sp.lambdify((x, u), f, 'numpy')
        A_func = sp.lambdify((x, u), A, 'numpy')
        B_func = sp.lambdify((x, u), B, 'numpy')

        return f_func, A_func, B_func 
开发者ID:EmbersArc,项目名称:SCvx,代码行数:24,代码来源:diffdrive_2d.py

示例3: as_matrix

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Matrix [as 别名]
def as_matrix(self):
        """Returns the data of the table in Matrix form.

        Examples
        ========
        >>> from sympy import TableForm
        >>> t = TableForm([[5, 7], [4, 2], [10, 3]], headings='automatic')
        >>> t
          | 1  2
        --------
        1 | 5  7
        2 | 4  2
        3 | 10 3
        >>> t.as_matrix()
        Matrix([
        [ 5, 7],
        [ 4, 2],
        [10, 3]])
        """
        from sympy import Matrix
        return Matrix(self._lines) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:23,代码来源:tableform.py

示例4: prepare_channel_operator_list

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Matrix [as 别名]
def prepare_channel_operator_list(ops_list):
        """
        Prepares a list of channel operators.

        Args:
            ops_list (List): The list of operators to prepare

        Returns:
            List: The channel operator list
        """
        # convert to sympy matrices and verify that each singleton is
        # in a tuple; also add identity matrix
        from sympy import Matrix, eye
        result = []
        for ops in ops_list:
            if not isinstance(ops, tuple) and not isinstance(ops, list):
                ops = [ops]
            result.append([Matrix(op) for op in ops])
        n = result[0][0].shape[0]  # grab the dimensions from the first element
        result = [[eye(n)]] + result
        return result

    # pylint: disable=invalid-name 
开发者ID:Qiskit,项目名称:qiskit-aer,代码行数:25,代码来源:noise_transformation.py

示例5: generate_channel_quadratic_programming_matrices

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Matrix [as 别名]
def generate_channel_quadratic_programming_matrices(
            self, channel, symbols):
        """
        Generate matrices for quadratic program.

        Args:
             channel (Matrix): a 4x4 symbolic matrix
             symbols (list): the symbols x1, ..., xn which may occur in the matrix

        Returns:
            list: A list of 4x4 complex matrices ([D1, D2, ..., Dn], E) such that:
            channel == x1*D1 + ... + xn*Dn + E
        """
        return (
            [self.get_matrix_from_channel(channel, symbol) for symbol in symbols],
            self.get_const_matrix_from_channel(channel, symbols)
        ) 
开发者ID:Qiskit,项目名称:qiskit-aer,代码行数:19,代码来源:noise_transformation.py

示例6: main

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Matrix [as 别名]
def main():
    Format()
    a = Matrix ( 2, 2, ( 1, 2, 3, 4 ) )
    b = Matrix ( 2, 1, ( 5, 6 ) )
    c = a * b
    print(a,b,'=',c)

    x, y = symbols ( 'x, y' )

    d = Matrix ( 1, 2, ( x ** 3, y ** 3 ))
    e = Matrix ( 2, 2, ( x ** 2, 2 * x * y, 2 * x * y, y ** 2 ) )
    f = d * e

    print('%',d,e,'=',f)

    # xpdf()
    xpdf(pdfprog=None)
    return 
开发者ID:pygae,项目名称:galgebra,代码行数:20,代码来源:matrix_latex.py

示例7: main

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Matrix [as 别名]
def main():
    Format()
    a = Matrix ( 2, 2, ( 1, 2, 3, 4 ) )
    b = Matrix ( 2, 1, ( 5, 6 ) )
    c = a * b
    print(a,b,'=',c)

    x, y = symbols ('x, y')

    d = Matrix ( 1, 2, ( x ** 3, y ** 3 ))
    e = Matrix ( 2, 2, ( x ** 2, 2 * x * y, 2 * x * y, y ** 2 ) )
    f = d * e

    print('%',d,e,'=',f)

    # xpdf()
    xpdf(pdfprog=None)
    return 
开发者ID:pygae,项目名称:galgebra,代码行数:20,代码来源:matrix_latex.py

示例8: test_conv10

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Matrix [as 别名]
def test_conv10():
    A = DenseMatrix(1, 4, [Integer(1), Integer(2), Integer(3), Integer(4)])
    assert (A._sympy_() == sympy.Matrix(1, 4,
                                        [sympy.Integer(1), sympy.Integer(2),
                                         sympy.Integer(3), sympy.Integer(4)]))

    B = DenseMatrix(4, 1, [Symbol("x"), Symbol("y"), Symbol("z"), Symbol("t")])
    assert (B._sympy_() == sympy.Matrix(4, 1,
                                        [sympy.Symbol("x"), sympy.Symbol("y"),
                                         sympy.Symbol("z"), sympy.Symbol("t")])
            )

    C = DenseMatrix(2, 2,
                    [Integer(5), Symbol("x"),
                     function_symbol("f", Symbol("x")), 1 + I])

    assert (C._sympy_() ==
            sympy.Matrix([[5, sympy.Symbol("x")],
                          [sympy.Function("f")(sympy.Symbol("x")),
                           1 + sympy.I]])) 
开发者ID:symengine,项目名称:symengine.py,代码行数:22,代码来源:test_sympy_conv.py

示例9: test_conv10b

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Matrix [as 别名]
def test_conv10b():
    A = sympy.Matrix([[sympy.Symbol("x"), sympy.Symbol("y")],
                     [sympy.Symbol("z"), sympy.Symbol("t")]])
    assert sympify(A) == DenseMatrix(2, 2, [Symbol("x"), Symbol("y"),
                                            Symbol("z"), Symbol("t")])

    B = sympy.Matrix([[1, 2], [3, 4]])
    assert sympify(B) == DenseMatrix(2, 2, [Integer(1), Integer(2), Integer(3),
                                            Integer(4)])

    C = sympy.Matrix([[7, sympy.Symbol("y")],
                     [sympy.Function("g")(sympy.Symbol("z")), 3 + 2*sympy.I]])
    assert sympify(C) == DenseMatrix(2, 2, [Integer(7), Symbol("y"),
                                            function_symbol("g",
                                                            Symbol("z")),
                                            3 + 2*I]) 
开发者ID:symengine,项目名称:symengine.py,代码行数:18,代码来源:test_sympy_conv.py

示例10: _qsympify_sequence

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Matrix [as 别名]
def _qsympify_sequence(seq):
    """Convert elements of a sequence to standard form.

    This is like sympify, but it performs special logic for arguments passed
    to QExpr. The following conversions are done:

    * (list, tuple, Tuple) => _qsympify_sequence each element and convert
      sequence to a Tuple.
    * basestring => Symbol
    * Matrix => Matrix
    * other => sympify

    Strings are passed to Symbol, not sympify to make sure that variables like
    'pi' are kept as Symbols, not the SymPy built-in number subclasses.

    Examples
    ========

    >>> from sympsi.qexpr import _qsympify_sequence
    >>> _qsympify_sequence((1,2,[3,4,[1,]]))
    (1, 2, (3, 4, (1,)))

    """

    return tuple(__qsympify_sequence_helper(seq)) 
开发者ID:sympsi,项目名称:sympsi,代码行数:27,代码来源:qexpr.py

示例11: _findIndex

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Matrix [as 别名]
def _findIndex(eq_vec, expr):
    """
    Given a vector of expressions, find where you will locate the
    input term.

    Parameters
    ----------
    eq_vec: :class:`sympy.Matrix`
        vector of sympy equation
    expr: sympy type
        An expression that we would like to find

    Returns
    -------
    list:
        of index that contains the expression.  Can be an empty list
        or with multiple integer
    """
    out = list()
    for i, a in enumerate(eq_vec):
        j = _hasExpression(a, expr)
        if j is True:
            out.append(i)
    return out 
开发者ID:publichealthengland,项目名称:pygom,代码行数:26,代码来源:_ode_composition.py

示例12: pureTransitionToOde

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Matrix [as 别名]
def pureTransitionToOde(A):
    """
    Get the ode from a pure transition matrix

    Parameters
    ----------
    A: `sympy.Matrix`
        a transition matrix of size [n \times n]

    Returns
    -------
    b: `sympy.Matrix`
        a matrix of size [n \times 1] which is the ode
    """
    nrow, ncol = A.shape
    assert nrow == ncol, "Need a square matrix"
    B = [sum(A[:, i]) - sum(A[i, :]) for i in range(nrow)]
    return sympy.simplify(sympy.Matrix(B)) 
开发者ID:publichealthengland,项目名称:pygom,代码行数:20,代码来源:_ode_composition.py

示例13: _generateTransitionMatrix

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Matrix [as 别名]
def _generateTransitionMatrix(self, A=None):#, transitionExpressionList=None):
        '''
        Finds the transition matrix from the set of ode.  It is
        important to note that although some of the functions used
        in this method appear to be the same as _getReactantMatrix
        and _getStateChangeMatrix, they are different in the sense
        that the functions called here is focused on the terms of
        the equation rather than the states.
        '''
        if A is None:
            if not ode_utils.none_or_empty_list(self._odeList):
                eqn_list = [t.equation for t in self._odeList]
                A = sympy.Matrix(checkEquation(eqn_list,
                                               *self._getListOfVariablesDict(),
                                               subs_derived=False))
            else:
                raise Exception("Object was not initialized using a set of ode")

        bdList, _term = _ode_composition.getUnmatchedExpressionVector(A, True)
        fx = _ode_composition.stripBDFromOde(A, bdList)
        states = [s for s in self._iterStateList()]
        M, _remain = _ode_composition.odeToPureTransition(fx, states, True)
        return M 
开发者ID:publichealthengland,项目名称:pygom,代码行数:25,代码来源:simulate.py

示例14: linearize_symbolic

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Matrix [as 别名]
def linearize_symbolic(self,
                            zeros=False) -> List[sympy.MutableDenseMatrix]:
        nx = len(self.x)
        nu = len(self.u)
        ny = len(self.y)
        nf = len(self.f)
        ng = len(self.g)
        A = sympy.Matrix([]) if zeros == False else sympy.Matrix.zeros(nx, nx)
        B = sympy.Matrix([]) if zeros == False else sympy.Matrix.zeros(nx, nu)
        C = sympy.Matrix([]) if zeros == False else sympy.Matrix.zeros(ny, nx)
        D = sympy.Matrix([]) if zeros == False else sympy.Matrix.zeros(ny, nu)
        if nx > 0:
            if nf > 0:
                A = self.f.jacobian(self.x)
            if ng > 0:
                C = self.g.jacobian(self.x)
        if nu > 0:
            if nf > 0:
                B = self.f.jacobian(self.u)
            if ng > 0:
                D = self.g.jacobian(self.u)
        return [A, B, C, D] 
开发者ID:pymoca,项目名称:pymoca,代码行数:24,代码来源:runtime.py

示例15: fcts

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Matrix [as 别名]
def fcts(self):

        j = sympy.Matrix([
            r**2 * sympy.sin(t) * z,
            r * sympy.sin(t) * z,
            r * sympy.sin(t) * z**2,
        ])

        # Create an isotropic sigma vector
        Sig = sympy.Matrix([
            [1120/(69*sympy.pi)*(r*z)**2 * sympy.sin(t)**2, 0, 0],
            [0, 1120/(69*sympy.pi)*(r*z)**2 * sympy.sin(t)**2, 0],
            [0, 0, 1120/(69*sympy.pi)*(r*z)**2 * sympy.sin(t)**2]
        ])

        return j, Sig 
开发者ID:simpeg,项目名称:discretize,代码行数:18,代码来源:test_cylOperators.py


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