當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。