Пример #1
0
def det(M):
    # check dimension of M
    m, n = M.shape
    if (m != n):
        print('It is not a square matrix, no determinant define !')
    else:
        # U : upper triangular (row echelon matrix)
        # nre : number of row-exchange
        U, rank, nre = LA.upperTri(M)

        # the determinant of M is the product of U[i,i]
        determinant = 1
        for i in range(m):
            determinant = determinant * U[i, i]

        # number of row-exchange will decide the sign
        if (nre % 2 == 1):  # nre is odd
            determinant = -1 * determinant
        # determinant = LA.det(M)
        return determinant
Пример #2
0
def det(M):
    # check dimension of M
    m,n = M.shape
    if (m!=n):
        print('It is not a square matrix, no determinant define !')
    else :
        # U : upper triangular (row echelon matrix)
        # nre : number of row-exchange
        U,rank,nre = LA.upperTri(M)
        
        # the determinant of M is the product of U[i,i]
        determinant = 1;
        for i in range(m):
            determinant = determinant*U[i,i]

        # number of row-exchange will decide the sign
        if (nre%2==1): # nre is odd
            determinant = -1*determinant
        # determinant = LA.det(M)
        return determinant
Пример #3
0
# -*- coding: utf-8 -*-
"""
Created on Sat Oct 15 2015

Modified on Fri Oct 15 2015

@author: david

"""

import LA
import numpy as np

#A=np.array([[1,2,1],[4,5,2],[4,8,3]])
A=np.array([[1,2],[4,5],[7,8]])
#A=np.array([[0,2,3],[0,5,6],[0,8,9]])
#A=np.array([[1,2,3],[3,5,6]])
print(A)
U=LA.upperTri(A)
R=LA.rref(A)
print(U)
print(R)
print(LA.det(A))
print(LA.inv(A))
b=np.array([3,6,9])
print(LA.solve(A,b))
Пример #4
0
# -*- coding: utf-8 -*-
"""
Created on Sat Oct 15 2015

Modified on Fri Oct 15 2015

@author: david

"""

import LA
import numpy as np

# A=np.array([[1,2,1],[4,5,2],[4,8,3]])
A = np.array([[1, 2], [4, 5], [7, 8]])
# A=np.array([[0,2,3],[0,5,6],[0,8,9]])
# A=np.array([[1,2,3],[3,5,6]])
print(A)
U = LA.upperTri(A)
R = LA.rref(A)
print(U)
print(R)
print(LA.det(A))
print(LA.inv(A))
b = np.array([3, 6, 9])
print(LA.solve(A, b))