To write a program to find the 1-norm, 2-norm and infinity norm of the matrix and display the result in two decimal places.
- Hardware – PCs
- Anaconda – Python 3.7 Installation / Moodle-Code Runner
- Get the input matrix using np.array()
- Find the 1-norm , 2-norm , infinity-norm of the matrix using np.linalg.norm()
- Print the norm of the matrix in two decimal places.
Developed by: yourname : S.M.Syed Mokthiyar
RegisterNumber: 22006227
(i) 1-norm
# program to find 1-norm of a matrix.
'''
import numpy as np
mat = np.array(eval(input()))
ans = np.linalg.norm(mat,1)
Norm_of_matrix = "{:.2f}".format(ans)
print(Norm_of_matrix)
(ii) 2-norm
# program to find 2-norm of a matrix.
import numpy as np
mat = np.array(eval(input()))
ans = np.linalg.norm(mat,2)
Norm_of_matrix = "{:.2f}".format(ans)
print(Norm_of_matrix)
(iii) 3-infinity
# program to find infinity-norm of a matrix.
import numpy as np
mat = np.array(eval(input()))
ans = np.linalg.norm(mat,np.inf)
Norm_of_matrix = "{:.2f}".format(ans)
print(Norm_of_matrix)
Thus the program for 1-norm, 2-norm and Infinity norm of a matrix are written and verified.