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


Python Matrix.inv方法代码示例

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


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

示例1: test_inverse

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import inv [as 别名]
def test_inverse():
    A = eye(4)
    assert A.inv() == eye(4)
    assert A.inv("LU") == eye(4)
    assert A.inv("ADJ") == eye(4)
    A = Matrix([[2,3,5],
                [3,6,2],
                [8,3,6]])
    Ainv = A.inv()
    assert A*Ainv == eye(3)
    assert A.inv("LU") == Ainv
    assert A.inv("ADJ") == Ainv
开发者ID:Lucaweihs,项目名称:sympy,代码行数:14,代码来源:test_matrices.py

示例2: Newton_solver_gxgt

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import inv [as 别名]
def Newton_solver_gxgt(error, hx, ht, x0, p_value=1, q_value=1):
    
    gx, gt, p, q, hx1, hx2, ht1, ht2  = symbols('gx gt p q qhx1 hx2 ht1 ht2')
    epsilon1 = gx*hx1**p + gt*ht1**q - error[-2]
    epsilon2 = gx*hx2**p + gt*ht2**q - error[-1]


    epsilon = [epsilon1, epsilon2]
    x = [gx, gt]
    knowns = [p, q, hx1, hx2, ht1, ht2]
    
    def f(i,j):
        return diff(epsilon[i], x[j])
        
    Jacobi = Matrix(2, 2, f)

    JacobiInv = Jacobi.inv()
    epsilonfunc = lambdify([x, knowns], epsilon)
    JacobiInvfunc = lambdify([x, knowns], JacobiInv)
    x = x0
    knowns = [p_value, q_value, hx[-2], hx[-1], ht[-2], ht[-1]]
    F = np.asarray(epsilonfunc(x, knowns))
    
    for n in range(8):
        Jinv = np.asarray(JacobiInvfunc(x, knowns))
        F = np.asarray(epsilonfunc(x, knowns))
        x = x - np.dot(Jinv, F)

        print "n, x: ", n, x
    
    return x
开发者ID:lrhgit,项目名称:tkt4140,代码行数:33,代码来源:sympy_Newton_solver.py

示例3: _compute_joint_acceleration

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import inv [as 别名]
def _compute_joint_acceleration(model, robo, j, i):
    """
    Compute the joint acceleration for joint j.

    Args:
        model: An instance of DynModel
        robo: An instance of Robot
        j: link number
        i: antecedent value

    Returns:
        An instance of DynModel that contains all the new values.
    """
    # local variables
    j_a_j = robo.geos[j].axisa
    j_s_i = robo.geos[j].tmat.s_j_wrt_i
    j_gamma_j = model.gammas[j].val
    j_inertia_j_s = model.star_inertias[j].val
    j_beta_j_s = model.star_betas[j].val
    h_j = Matrix([model.joint_inertias[j]])
    tau_j = Matrix([model.taus[j]])
    i_vdot_i = model.accels[i].val
    # actual computation
    qddot_j = h_j.inv() * (-j_a_j.transpose() * j_inertia_j_s * \
        ((j_s_i * i_vdot_i) + j_gamma_j) + tau_j + \
        (j_a_j.transpose() * j_beta_j_s))
    # store in model
    model.qddots[j] = qddot_j[0, 0]
    return model
开发者ID:ELZo3,项目名称:symoro,代码行数:31,代码来源:dynmodel.py

示例4: _compute_alpha_wrench

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import inv [as 别名]
def _compute_alpha_wrench(model, robo, j):
    """
    Compute the wrench as a function of tau - joint torque without
    friction.

    Args:
        model: An instance of DynModel
        robo: An instance of Robot
        j: joint number

    Returns:
        An instance of DynModel that contains all the new values.
    """
    j_alpha_j = Screw()
    # local variables
    j_a_j = robo.geos[j].axisa
    j_k_j = model.no_qddot_inertias[j].val
    j_gamma_j = model.gammas[j].val
    j_inertia_j_s = model.star_inertias[j].val
    j_beta_j_s = model.star_betas[j].val
    h_j = Matrix([model.joint_inertias[j]])
    tau_j = Matrix([model.taus[j]])
    # actual computation
    j_alpha_j.val = (j_k_j * j_gamma_j) + \
        (j_inertia_j_s * j_a_j * h_j.inv() * \
        (tau_j + j_a_j.transpose() * j_beta_j_s)) - j_beta_j_s
    # store in model
    model.alphas[j] = j_alpha_j
    return model
开发者ID:ELZo3,项目名称:symoro,代码行数:31,代码来源:dynmodel.py

示例5: Newton_solver_pq

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import inv [as 别名]
def Newton_solver_pq(error, hx, ht, gx, gt, x0):
    
    p, q  = symbols('p q')
    
    epsilon1 = gx*hx[-2]**p + gt*ht[-2]**q - error[-2]
    epsilon2 = gx*hx[-1]**p + gt*ht[-1]**q - error[-1]


    epsilon = [epsilon1, epsilon2]
    x = [p, q]
    
    def f(i,j):
        return diff(epsilon[i], x[j])
        
    Jacobi = Matrix(2, 2, f)

    JacobiInv = Jacobi.inv()
    epsilonfunc = lambdify(x, epsilon)
    JacobiInvfunc = lambdify(x, JacobiInv)
    x = x0
    
    
    

    F = np.asarray(epsilonfunc(x))
    
    for n in range(8):
        Jinv = np.asarray(JacobiInvfunc(x))
        F = np.asarray(epsilonfunc(x))
        x = x - np.dot(Jinv, F)

    return x
开发者ID:lrhgit,项目名称:tkt4140,代码行数:34,代码来源:sympy_Newton_solver.py

示例6: tet4

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import inv [as 别名]
def tet4():
    N1 = z
    N2 = n
    N3 = b
    N4 = 1 - z - n - b

    X = Matrix([[1, x, y, z]])
    X2 = Matrix([[1, x1, y1, z1],
                 [1, x2, y2, z2],
                 [1, x3, y3, z3],
                 [1, x4, y4, z4]])
    N = X * X2.inv()
    N1 = N[0, 0]
    N2 = N[0, 1]
    N3 = N[0, 2]
    N4 = N[0, 3]

    N = Matrix([[N1, 0, 0, N2, 0, 0, N3, 0, 0, N4, 0, 0],
                [0, N1, 0, 0, N2, 0, 0, N3, 0, 0, N4, 0],
                [0, 0, N1, 0, 0, N2, 0, 0, N3, 0, 0, N4]])
    NT = N.transpose()
    #pdV = p*v
    pdV = 3
    factorI = 1
    M = makeM(pdV, NT, factorI, levels=3)
    print "Mtet = \n", M
开发者ID:xirxa,项目名称:pynastran-locr,代码行数:28,代码来源:massMatrix.py

示例7: _estimate_gradients_2d_global

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

    #
    # Compute
    #
    #

    f1, f2, df1, df2, x = symbols(['f1', 'f2', 'df1', 'df2', 'x'])
    c = [f1, (df1 + 3*f1)/3, (df2 + 3*f2)/3, f2]

    w = 0
    for k in range(4):
        w += binomial(3, k) * c[k] * x**k*(1-x)**(3-k)

    wpp = w.diff(x, 2).expand()
    intwpp2 = (wpp**2).integrate((x, 0, 1)).expand()

    A = Matrix([[intwpp2.coeff(df1**2), intwpp2.coeff(df1*df2)/2],
                [intwpp2.coeff(df1*df2)/2, intwpp2.coeff(df2**2)]])

    B = Matrix([[intwpp2.coeff(df1).subs(df2, 0)],
                [intwpp2.coeff(df2).subs(df1, 0)]]) / 2

    print("A")
    print(A)
    print("B")
    print(B)
    print("solution")
    print(A.inv() * B)
开发者ID:BranYang,项目名称:scipy,代码行数:31,代码来源:interpnd_info.py

示例8: MatrizInversa

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import inv [as 别名]
def MatrizInversa(a, b,lista):
    
    ma = json.loads(a)
    
    mb = json.loads(b)
    
    A = Matrix(ma)
    
    B = Matrix(mb)
    
    try:
    
        A_inv = A.inv()
    
    except ValueError:
    
        lista.append('\n')
    
        lista.append( 'Matriz es singular, no se puede resolver!')
    
        lista.append('\n') 
    
    else:
    
        ans = A_inv*B
    
        MA = A.tolist()
    
        MB = B.tolist()
开发者ID:Guillermo2013,项目名称:ProyectoMetodosNumericos,代码行数:31,代码来源:MatrizInversa.py

示例9: newton

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import inv [as 别名]
def newton():
    x1 = Symbol("x1")
    y1 = Symbol("y1")
    m = 0.2
    a = 0.7
    e = 0.0001
    f1 = tan(x1 * y1 + m) - x1
    f2 = a * x1 ** 2 + 2 * y1 ** 2 - 1
    y11 = diff(f1, x1)
    y12 = diff(f1, y1)
    y21 = diff(f2, x1)
    y22 = diff(f2, y1)
    j = Matrix([[y11, y12], [y21, y22]])
    j1 = j.inv()
    x0 = 0.75
    y0 = 0.4
    xn = x0 - j1[0, 0].subs(x1, x0).subs(y1, y0) * f1.subs(x1, x0).subs(y1, y0)
    - j1[0, 1].subs(x1, x0).subs(y1, y0) * f2.subs(x1, x0).subs(y1, y0)
    yn = y0 - j1[1, 0].subs(x1, x0).subs(y1, y0) * f1.subs(x1, x0).subs(y1, y0)
    - j1[1, 1].subs(x1, x0).subs(y1, y0) * f2.subs(x1, x0).subs(y1, y0)
    count2 = 0
    while (abs(xn - x0) > e) or (abs(yn - y0) > e):
        x0 = xn
        y0 = yn
        calcul = j1[0, 0].subs(x1, x0).subs(y1, y0) * f1.subs(x1, x0).subs(y1, y0) - j1[0, 1].subs(x1, x0).subs(y1, y0) * f2.subs(x1, x0).subs(y1, y0)
        xn = x0 - calcul
        yn = y0 - j1[1, 0].subs(x1, x0).subs(y1, y0) * f1.subs(x1, x0).subs(y1, y0) - j1[1, 1].subs(x1, x0).subs(y1, y0) * f2.subs(x1, x0).subs(y1, y0)

        count2 += 1
    print("x = ", xn, " ", "y = ", yn, " - ", count2, " iterations")
    print("graph processing...")
    plot_implicit(Or(Eq(a * x1 ** 2 + 2 * y1 ** 2, 1), Eq(tan(x1 * y1 + m) - x1, 0)), (x1, -5, 5), (y1, -5, 5))
开发者ID:keipa,项目名称:bsuir-labs,代码行数:34,代码来源:main.py

示例10: generate_base_change_matrix

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import inv [as 别名]
 def generate_base_change_matrix(size = 8):
     ''' Builds the matrix. '''
     if using_sympy:
         A = Matrix([ Polynomial.choose(k).pad_with_zeroes(size)
                                                         for k in range(size) ])
         A = A.transpose()
         Polynomial.base_change_matrix = A.inv()
     elif using_sage:
         print('eh, ill do this later')
     else:
         print('need sympy or sage')
开发者ID:cheyneh,项目名称:polypermclass,代码行数:13,代码来源:polypermclass.py

示例11: Newton_solver_sympy

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import inv [as 别名]
 def Newton_solver_sympy(error, h, x0):
     """ Function that solves for the nonlinear set of equations
         error1 = C*h1^p --> f1 = C*h1^p - error1 = 0
         error2 = C*h2^p --> f2 = C h2^p - error 2 = 0
         where C is a constant h is the step length and p is the order,
         with use of a newton rhapson solver. In this case C and p are
         the unknowns, whereas h and error are knowns. The newton rhapson 
         method is an iterative solver which take the form:
         xnew = xold - (J^-1)*F, where J is the Jacobi matrix and F is the 
         residual funcion.
             x = [C, p]^T
             J = [[df1/dx1  df2/dx2],
                  [df2/dx1  df2/dx2]]
             F = [f1, f2]
         This is very neatly done with use of the sympy module
         
         Args:
             error(list): list of calculated errors [error(h1), error(h2)]
             h(list): list of steplengths corresponding to the list of errors
             x0(list): list of starting (guessed) values for x
         
         Returns:
             x(array): iterated solution of x = [C, p]
 
     """
     from sympy import Matrix
     #### Symbolic computiations: ####
     C, p = symbols('C p')
     f1 = C*h[-2]**p - error[-2]
     f2 = C*h[-1]**p - error[-1]
     F = [f1, f2]
     x = [C, p]
     
     def jacobiElement(i,j):
         return diff(F[i], x[j])
         
     Jacobi = Matrix(2, 2, jacobiElement) # neat way of computing the Jacobi Matrix
     JacobiInv = Jacobi.inv()
     #### Numerical computations: ####
     JacobiInvfunc = lambdify([x], JacobiInv)
     Ffunc = lambdify([x], F)
     x = x0
     
     for n in range(8): #perform 8 iterations
         F = np.asarray(Ffunc(x))
         Jinv = np.asarray(JacobiInvfunc(x))
         xnew = x - np.dot(Jinv, F)
         x = xnew
         #print "n, x: ", n, x
     x[0] = round(x[0], 2)
     x[1] = round(x[1], 3)
     return x
开发者ID:lrhgit,项目名称:tkt4140,代码行数:54,代码来源:ODEschemes.py

示例12: _make_expr_01

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import inv [as 别名]
def _make_expr_01():
    
    C = Matrix(3, 3, symbols('C00, C01, C02, C10, C11, C12, C20, C21, C22'))

    F = Matrix(3, 3, symbols('F00, F01, F02, F10, F11, F12, F20, F21, F22'))

    Fg = Matrix(3, 3, symbols('Fg11, Fg12, Fg13, Fg21, Fg22, Fg23, Fg31, Fg32, Fg33'))

    Fg_inv=Fg.inv()

    Ce=Fg_inv.T*C*Fg_inv

    Cedet=Ce.berkowitz_det()

    return Cedet
开发者ID:lianggecm,项目名称:Sympy_Codes,代码行数:17,代码来源:codegenperf.py

示例13: test_mat_inv_mul

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import inv [as 别名]
def test_mat_inv_mul():
    # Uses SymPy generated primes as matrix entries, so each entry in
    # each matrix should be symbolic and unique, allowing proper comparison.
    # Checks _mat_inv_mul against Matrix.inv / Matrix.__mul__.
    from sympy import Matrix, prime

    # going to form 3 matrices
    # 1 n x n
    # different n x n
    # 1 n x 2n
    n = 3
    m1 = Matrix(n, n, lambda i, j: prime(i * n + j + 2))
    m2 = Matrix(n, n, lambda i, j: prime(i * n + j + 5))
    m3 = Matrix(n, n, lambda i, j: prime(i + j * n + 2))

    assert _mat_inv_mul(m1, m2) == m1.inv() * m2
    assert _mat_inv_mul(m1, m3) == m1.inv() * m3
开发者ID:B-Rich,项目名称:sympy,代码行数:19,代码来源:test_functions.py

示例14: Newton_solver_All

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import inv [as 别名]
def Newton_solver_All(error, hx, ht, x0):
    
    gx, p, gt, q  = symbols('gx p gt q')
    hx1, hx2, hx3, hx4, ht1, ht2, ht3, ht4 = symbols('hx1 hx2 hx3 hx4 ht1 ht2 ht3 ht4')
    epsilon1 = gx*hx1**p + gt*ht1**q - error[-4]
    epsilon2 = gx*hx2**p + gt*ht2**q - error[-3]
    epsilon3 = gx*hx3**p + gt*ht3**q - error[-2]
    epsilon4 = gx*hx4**p + gt*ht4**q - error[-1]

    epsilon = [epsilon1, epsilon2, epsilon3, epsilon4]
    x = [gx, p, gt, q]
    knowns = [hx1, hx2, hx3, hx4, ht1, ht2, ht3, ht4]
    
    def f(i,j):
        return diff(epsilon[i], x[j])
        
    Jacobi = Matrix(4, 4, f)

    JacobiInv = Jacobi.inv()
    epsilonfunc = lambdify([x, knowns], epsilon)
    JacobiInvfunc = lambdify([x, knowns], JacobiInv)
    x = x0
    knowns = [hx[-4], hx[-3], hx[-2], hx[-1], ht[-4], ht[-3], ht[-2], ht[-1]]

    
    print "knowns: ", knowns
    
    try:
        Jinv = np.asarray(JacobiInvfunc(x, knowns))
    except:
        print "print unable to invert jacobi matrix"
        Jinv = None
    F = np.asarray(epsilonfunc(x, knowns))
    
    for n in range(8):
        if Jinv != None:
            xnew = x - np.dot(Jinv, F)
            F = np.asarray(epsilonfunc(xnew, knowns))
            try:
                Jinv = np.asarray(JacobiInvfunc(x, knowns))
            except:
                print " unable to invert jacobi matrix"
                Jinv = None
            
            x = xnew
            print "n, x: ", n, x
开发者ID:lrhgit,项目名称:tkt4140,代码行数:48,代码来源:sympy_Newton_solver.py

示例15: test_mat_inv_mul

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import inv [as 别名]
def test_mat_inv_mul():
    # Just a quick test to check that KanesMethod._mat_inv_mul works as
    # intended. Uses SymPy generated primes as matrix entries, so each entry in
    # each matrix should be symbolic and unique, allowing proper comparison.
    # Checks _mat_inv_mul against Matrix.inv / Matrix.__mul__.
    from sympy import Matrix, prime
    from sympy.physics.mechanics import ReferenceFrame, KanesMethod

    # Just need to create an instance of KanesMethod to get to _mat_inv_mul
    mat_inv_mul = KanesMethod(ReferenceFrame('N'), [1], [1])._mat_inv_mul

    # going to form 3 matrices
    # 1 n x n
    # different n x n
    # 1 n x 2n
    n = 3
    m1 = Matrix(n, n, lambda i, j: prime(i * n + j + 2))
    m2 = Matrix(n, n, lambda i, j: prime(i * n + j + 5))
    m3 = Matrix(n, n, lambda i, j: prime(i + j * n + 2))

    assert mat_inv_mul(m1, m2) == m1.inv() * m2
    assert mat_inv_mul(m1, m3) == m1.inv() * m3
开发者ID:Acebulf,项目名称:sympy,代码行数:24,代码来源:test_kane2.py


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