import numpy as np

A=np.array([[1.5,1],[3.75,4]])

B=np.array([1800,900])

x=np.linalg.solve(A,B)

print("Values of A and B variables:",x)

h=np.allclose(np.dot(A, x), B)

print("Substitution of two variables in equation to validate:",h)

### Operations on Matrices using Python program

import numpy as np

A = np.array([[4,1,7],[2,1,8],[3 ,7,1]])

B = np.array([[6,1,1],[2,1,5],[2,3,1]])

C=A.dot(B)

print("Values of First 2D Matrix\n",A)

print("Values of Second 2D Matrix\n",B)

print("---------------------------------------------")

print("Multiplication of Matrices\n",C)

print("\n")

Ainv=np.linalg.inv(A)

Binv=np.linalg.inv(B)

print("Inverse of First Matrix\n",Ainv)

print("Inverse of Second Matrix\n",Binv)

print("\n")

AI=Ainv.dot(A)

BI=Binv.dot(B)

print("Multiplication of First Matrix and their Inverse\n",AI)

print("Multiplication of Second Matrix and their Inverse\n",BI)

AD=np.linalg.det(A)

BD=np.linalg.det(B)

print("\n")

print("Determinant of First Matricx:",AD)

print("Determinant of Second Matricx:",BD)

print("\n")

ADi=np.diag(A)

BDi=np.diag(B)

print("Diagonal Elements of First Matrix:",ADi)

print("Diagonal Elements of Second Matrix:",BDi)

SADi=np.trace(A)

SBDi=np.trace(B)

print("\n")

print("Sum of Diagonal Elements of First Matrix:",SADi)

print("Sum of Diagonal Elements of Second Matrix:",SBDi)

print("\n")

CA=np.cov(A)

CB=np.cov(B)

print("Covariance matrix of First Matrix\n",CA)

print("Covariance matrix of Second Matrix\n",CB)

print("\n")

ECA=np.linalg.eigh(CA)

ECB=np.linalg.eigh(CB)

print("First array represents eigenvalues and second array represents eigenvectors")

print("\n")

print("covariance matrix eigenvalues eigenvectors of First Matrix\n",ECA)

print("\n")

print("covariance matrix eigenvalues eigenvectors of Second Matrix\n",ECB)

A = np.array([[4,1,7],[2,1,8],[3 ,7,1]])

B = np.array([[6,1,1],[2,1,5],[2,3,1]])

C=A.dot(B)

print("Values of First 2D Matrix\n",A)

print("Values of Second 2D Matrix\n",B)

print("---------------------------------------------")

print("Multiplication of Matrices\n",C)

print("\n")

Ainv=np.linalg.inv(A)

Binv=np.linalg.inv(B)

print("Inverse of First Matrix\n",Ainv)

print("Inverse of Second Matrix\n",Binv)

print("\n")

AI=Ainv.dot(A)

BI=Binv.dot(B)

print("Multiplication of First Matrix and their Inverse\n",AI)

print("Multiplication of Second Matrix and their Inverse\n",BI)

AD=np.linalg.det(A)

BD=np.linalg.det(B)

print("\n")

print("Determinant of First Matricx:",AD)

print("Determinant of Second Matricx:",BD)

print("\n")

ADi=np.diag(A)

BDi=np.diag(B)

print("Diagonal Elements of First Matrix:",ADi)

print("Diagonal Elements of Second Matrix:",BDi)

SADi=np.trace(A)

SBDi=np.trace(B)

print("\n")

print("Sum of Diagonal Elements of First Matrix:",SADi)

print("Sum of Diagonal Elements of Second Matrix:",SBDi)

print("\n")

CA=np.cov(A)

CB=np.cov(B)

print("Covariance matrix of First Matrix\n",CA)

print("Covariance matrix of Second Matrix\n",CB)

print("\n")

ECA=np.linalg.eigh(CA)

ECB=np.linalg.eigh(CB)

print("First array represents eigenvalues and second array represents eigenvectors")

print("\n")

print("covariance matrix eigenvalues eigenvectors of First Matrix\n",ECA)

print("\n")

print("covariance matrix eigenvalues eigenvectors of Second Matrix\n",ECB)

Subscribe to:
Posts (Atom)