Program to convert a matrix to a upper triangular form using Gauss elimination method and to find the determinant of the matrix.
# Program to convert a matrix to a upper triangular form using Gauss elimination method and to
# find the determinant of the matrix.
a=[]
n=input("Enter the dimension of the matrix:")
n=int(n)
for i in range(n):
r=input("Enter the elements of row "+str(i+1)+" :").split(",")
r=list(map(float,r))
a.append(r)
print("The entered matrix is:")
for i in range(n):
print (a[i])
for c in range(n-1):
for r in range(c+1,n):
l=a[r][c]/a[c][c]
for k in range(n):
a[r][k]=a[r][k]-l*a[c][k]
s=1.0
print("The entered matrix in upper triangular form is:")
for i in range(n):
print(a[i])
s=a[i][i]*s
print ("The determinant of the matrix is:",s)
# find the determinant of the matrix.
a=[]
n=input("Enter the dimension of the matrix:")
n=int(n)
for i in range(n):
r=input("Enter the elements of row "+str(i+1)+" :").split(",")
r=list(map(float,r))
a.append(r)
print("The entered matrix is:")
for i in range(n):
print (a[i])
for c in range(n-1):
for r in range(c+1,n):
l=a[r][c]/a[c][c]
for k in range(n):
a[r][k]=a[r][k]-l*a[c][k]
s=1.0
print("The entered matrix in upper triangular form is:")
for i in range(n):
print(a[i])
s=a[i][i]*s
print ("The determinant of the matrix is:",s)
Comments
Post a Comment