Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

inverse matrix gauss python

def inverse(a):
    n = len(a) #defining the range through which loops will run
    #constructing the n X 2n augmented matrix
    P = [[0.0 for i in range(len(a))] for j in range(len(a))]
    for i in range(3):
        for j in range(3):
            P[j][j] = 1.0
    for i in range(len(a)):
        a[i].extend(P[i])
    #main loop for gaussian elimination begins here
    for k in range(n):
        if abs(a[k][k]) < 1.0e-12:
            for i in range(k+1, n):
                if abs(a[i][k]) > abs(a[k][k]):
                    for j in range(k, 2*n):
                        a[k][j], a[i][j] = a[i][j], a[k][j] #swapping of rows
                    break
        pivot = a[k][k] #defining the pivot
        if pivot == 0: #checking if matrix is invertible
            print("This matrix is not invertible.")
            return
        else:
            for j in range(k, 2*n): #index of columns of the pivot row
                a[k][j] /= pivot
            for i in range(n): #index the subtracted rows
                if i == k or a[i][k] == 0: continue
                factor = a[i][k]
                for j in range(k, 2*n): #index the columns for subtraction
                    a[i][j] -= factor * a[k][j]
    for i in range(len(a)): #displaying the matrix
        for j in range(n, len(a[0])):
            print(a[i][j], end = " ")
        print()
Comment

PREVIOUS NEXT
Code Example
Python :: if a or b in python 
Python :: python << meaning 
Python :: pandas merge_asof direction 
Python :: img_sm = pygame.transform.scale(img, (32, 32)) 
Python :: print something after sec python 
Python :: File "main.py", line 21 print("total harga:idr", bakso bulat +str Minuman Drink): ^ SyntaxError: invalid syntax 
Python :: import .dat python 
Python :: generate 50 characters long for django 
Python :: how to set pywal permenent 
Python :: wxpython menu callback stackoverflow 
Python :: pss signatures python 
Python :: build an ai writer web crapper 
Python :: como fazer um bot spamm no discord com python 
Shell :: classic confinement requires snaps under /snap or symlink from /snap to /var/lib/snapd/snap 
Shell :: remove angular cli 
Shell :: react-scripts is not recognized as an internal command windows 
Shell :: set default branch to main on git init 
Shell :: stash untrack files 
Shell :: git username email 
Shell :: linux find files larger than 1gb 
Shell :: ubuntu disabling IPV6 
Shell :: firewalld not running centos 7 
Shell :: ubuntu play on linux install 
Shell :: spigot start.bat 
Shell :: install gparted ubuntu 
Shell :: how to get my ip address mac terminal 
Shell :: bison install ubuntu 
Shell :: how to see the remote url in git 
Shell :: linux check if a port is open 
Shell :: install portainer 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =