Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # I was able to only program for matrices of order 2 and 3
- # I'll soon improve and generalise it, for all order matrices
- def main() :
- M1 = []
- order = int(input("Enter the order of |A| (like 2 or 3) : "))
- if order in (2, 3) :
- for i in range(order) :
- temp = []
- for j in range(order) :
- elem = eval(input("Enter the Element of the Determinant at ; Row : {} , Column : {} =====> ".format(i+1,j+1)))
- temp.append(elem)
- M1.append(temp)
- print("\nThe Determinant : ")
- for i in M1 :
- print("| " , end = " ")
- for j in i :
- print(j , end = " ")
- print("|")
- if order == 2 :
- det = (M1[0][0]*M1[1][1]) - (M1[0][1]*M1[1][0])
- print("\nThe Value of the Determinant : {}".format(det))
- else :
- row_1 = (M1[0][0]*((M1[1][1]*M1[2][2]) - (M1[1][2]*M1[2][1])))
- row_2 = (M1[0][1]*((M1[1][0]*M1[2][2]) - (M1[1][2]*M1[2][0])))
- row_3 = (M1[0][2]*((M1[1][0]*M1[2][1]) - (M1[1][1]*M1[2][0])))
- det = row_1 - row_2 + row_3
- print("\nThe Value of the Determinant : {}".format(det))
- else : print("\nSorry for the Inconvinience!!! I haven't Programmed it to Calculate the Value of a Determinant of this order.")
- main()
Advertisement
Add Comment
Please, Sign In to add comment