0.1 Practice Problems:: January 8, 2021
0.1 Practice Problems:: January 8, 2021
January 8, 2021
[13]: A=np.array([[1,2,3],[4,5,6],[7,8,9]])
B=np.array([[-1,12,3],[8,15,-6],[17,20,4]])
x=np.add(A,B)
y=np.subtract(A,B)
z=np.multiply(A,A)
print(x)
print(y)
print(z)
[[ 0 14 6]
[12 20 0]
[24 28 13]]
[[ 2 -10 0]
[ -4 -10 12]
[-10 -12 5]]
[[ 1 4 9]
[16 25 36]
[49 64 81]]
2. Create a matrix M= [2,0,4] [3,8,2] [1,2,3] and fetch all the elements in the second column.
[14]: M=np.array([[2,0,4],[3,8,2],[1,2,3]])
print("ELEMENTS OF SECOND COLUMN is: ", M[:,1])
1
[[-2. 1. ]
[ 1.5 -0.5]]
EXAMPLE 2:
[21]: B=np.matrix([[21,25],[7,6]])
i=np.linalg.inv(B)
print(i)
[[-0.12244898 0.51020408]
[ 0.14285714 -0.42857143]]
EXAMPLE 3:
[22]: C=np.matrix([[1,-1,2],[0,2,-3],[3,-2,4]])
inverse=np.linalg.inv(C)
print(inverse)
[[-2. 0. 1.]
[ 9. 2. -3.]
[ 6. 1. -2.]]
0.3 EXERCISE:
Find the inverse of the following matrices
[23]: A=np.matrix([[1,2,3],[1,3,3],[2,4,3]])
inverse=np.linalg.inv(A)
print(inverse)
[24]: B=np.matrix([[1,2,-3],[0,1,2],[0,0,1]])
inverse=np.linalg.inv(B)
print(inverse)
[[ 1. -2. 7.]
[ 0. 1. -2.]
[ 0. 0. 1.]]
2
[25]: C=np.matrix([[1,2,3],[2,-3,1],[3,1,-2]])
inverse=np.linalg.inv(C)
print(inverse)
[[1.]
[2.]
[3.]]
[[ 3.]
[-2.]
[ 1.]]
0.5 Determinants
numpy.linalg.det() : This function is used to compute the determinant of the matrix
EXAMPLE 1: Evaluate the determinant of the matrix J= [3,-1,-2] [0,0,-1] [3,-5,0]
[28]: J=np.matrix([[3,-1,-2],[0,0,-1],[3,-5,0]])
print(np.linalg.det(J))
-12.0
3
[29]: P=np.matrix([[2,-3,5],[5,2,-7],[-4,3,1]])
print(np.linalg.det(P))
92.00000000000001
[ ]: