#Program to define a function which calculates the trace of a matrix:
def imatrix(m):
A=[]
for i in range(m):
a=input("Enter the elements of row "+str(i+1)+" :").split(",")
b=list(map(float,a))
A.append(b)
return A
def showm(A):
for i in range (m):
print (A[i])
def tracem(A):
k=0
for i in range (m):
k=k+A[i][i]
return k
m=input("Enter the dimension of the matrix:")
m=int(m)
X=imatrix(m)
print("The entered matrix is:")
showm(X)
Y=tracem(X)
print ("The trace of the matrix is:",Y)
def imatrix(m):
A=[]
for i in range(m):
a=input("Enter the elements of row "+str(i+1)+" :").split(",")
b=list(map(float,a))
A.append(b)
return A
def showm(A):
for i in range (m):
print (A[i])
def tracem(A):
k=0
for i in range (m):
k=k+A[i][i]
return k
m=input("Enter the dimension of the matrix:")
m=int(m)
X=imatrix(m)
print("The entered matrix is:")
showm(X)
Y=tracem(X)
print ("The trace of the matrix is:",Y)
Comments
Post a Comment