Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
52 views

0.1 Practice Problems:: January 8, 2021

The document discusses linear algebra concepts like matrix operations, inverse of matrices, solution of simultaneous linear equations, determinants, and eigenvalues. Various examples are provided to demonstrate computing inverse, determinant and eigenvalues of matrices using NumPy functions like inv(), det() and eigvals().

Uploaded by

RagaviSowmya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

0.1 Practice Problems:: January 8, 2021

The document discusses linear algebra concepts like matrix operations, inverse of matrices, solution of simultaneous linear equations, determinants, and eigenvalues. Various examples are provided to demonstrate computing inverse, determinant and eigenvalues of matrices using NumPy functions like inv(), det() and eigvals().

Uploaded by

RagaviSowmya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

2021-01-8

January 8, 2021

0.1 Practice Problems:


1. Contruct a matrix A=[1,2,3] [4,5,6] [7,8,9] and perform A+B, A-B, A2

[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])

ELEMENTS OF SECOND COLUMN is: [0 8 2]

0.2 Inverse of a Matrix


numpy.linalg.inv() : This command is used to compute the inverse of the matrix
EXAMPLE 1:
[20]: import numpy as np
A=np.matrix([[1,2],[3,4]])
inv=np.linalg.inv(A)
print(inv)

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

1. [1,2,3] [1,3,3] [2,4,3]

[23]: A=np.matrix([[1,2,3],[1,3,3],[2,4,3]])
inverse=np.linalg.inv(A)
print(inverse)

[[ 1.00000000e+00 -2.00000000e+00 1.00000000e+00]


[-1.00000000e+00 1.00000000e+00 -2.77555756e-17]
[ 6.66666667e-01 0.00000000e+00 -3.33333333e-01]]

2. [1,2,-3] [0,1,2] [0,0,1]

[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.]]

3. [1,2,3] [2,-3,1] [3,1,-2]

2
[25]: C=np.matrix([[1,2,3],[2,-3,1],[3,1,-2]])
inverse=np.linalg.inv(C)
print(inverse)

[[ 0.09615385 0.13461538 0.21153846]


[ 0.13461538 -0.21153846 0.09615385]
[ 0.21153846 0.09615385 -0.13461538]]

0.4 Solution of Simultaneous Linear Equations


Consider the set of simultaneous equations in x,y and z
a1x+b1y+c1z=d1 ; a2x+b2y+c2z=d2 ; a3x+b3y+c3z=d3
They can be expressed as the matrix form
AX = B
=> X= Aˆ(-1)B
EXAMPLE 1: Solve the system of equations 2x-3y+5z=11, 5x+2y-7z=-12, -4x+3y+z=5
[26]: P=np.matrix([[2,-3,5],[5,2,-7],[-4,3,1]])
Q=np.matrix([[11],[-12],[5]])
R=np.linalg.inv(P)
print(np.dot(R,Q))

[[1.]
[2.]
[3.]]

EXAMPLE 2: Solve the system of equations 3x-y+2z=13, 2x+y-z=3, x+3y-5z=-8


[27]: P=np.matrix([[3,-1,2],[2,1,-1],[1,3,-5]])
Q=np.matrix([[13],[3],[-8]])
R=np.linalg.inv(P)
print(np.dot(R,Q))

[[ 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

EXAMPLE 2: Evaluate the determinant of the matrix P= [2,-3,5] [5,2,-7] [-4,3,1]

3
[29]: P=np.matrix([[2,-3,5],[5,2,-7],[-4,3,1]])
print(np.linalg.det(P))

92.00000000000001

0.6 Eigen Values


numpy.linalg.eigvals() : This function is used to compute the eigen value of the matrix
EXAMPLE 1: Evaluate the eigen value of matrix S=[3,-1,-2] [0,0,-1] [3,-5,0]
[30]: S=np.matrix([[3,-1,-2],[0,0,-1],[3,-5,0]])
print(np.linalg.eigvals(S))

[-1.52216738+0.j 2.26108369+1.66463096j 2.26108369-1.66463096j]

[ ]:

You might also like