#Program to diagonalise a given matrix using Gauss Jordan method
a=[]
n=input("Enter the dimension of the matrix:")
n=int(n)
for i in range(n):
r=input("Enter the elements for 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(0,n):
for r in range(0,n):
if r!=c:
l=a[r][c]/a[c][c]
for k in range(n):
a[r][k]=a[r][k]-l*a[c][k]
print("The diagonalised matrix is:")
for i in range(n):
print(a[i])
a=[]
n=input("Enter the dimension of the matrix:")
n=int(n)
for i in range(n):
r=input("Enter the elements for 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(0,n):
for r in range(0,n):
if r!=c:
l=a[r][c]/a[c][c]
for k in range(n):
a[r][k]=a[r][k]-l*a[c][k]
print("The diagonalised matrix is:")
for i in range(n):
print(a[i])
Comments
Post a Comment