Professional Documents
Culture Documents
Practical 5 Application of Matrix
Practical 5 Application of Matrix
Class: S.Y.BCS
Roll number: 5039 batch :B
Practical Number :5 .
Practical Name:-Application of Matrices.
Q 1 Create row & column vector.
(i)
from sympy import*
Matrix([[1,2,3]])
#Output: Matrix([[1, 2, 3]])
(ii)
from sympy import*
Matrix([[1],[2],[3]])
#Output :-Matrix([
[1],
[2],
[3]])
u-v
#Output:-Matrix([
[ 1],
[ 5],
[-1]])
3*u
#Output:-Matrix([
[ 6],
[15],
[-9]])
2*u+3*v
#Output:-Matrix([
[ 7],
[ 10],
[-12]])
zeros(2,3)
#Output:-Matrix([
[0, 0, 0],
[0, 0, 0]])
ones(2,3)
#Output:-Matrix([
[1, 1, 1],
[1, 1, 1]])
diag(1,2,3)
#Output:-Matrix([
[1, 0, 0],
[0, 2, 0],
[0, 0, 3]])
Q.5 Find i) A+B ii) A-B iii) A*A iv) A*B v) A*V
vi) A**3 vii) B*A viii) B-1AB
A-B
#Output:-Matrix([
[-3, -4, 6],
[ 8, 4, 0],
[ 7, 0, 18]])
A*A
#Output:-Matrix([
[ 30, 36, 42],
[ 66, 81, 96],
[102, 126, 150]])
A*B
#Output:-Matrix([
[-4, 32, -18],
[-4, 77, -36],
[-4, 122, -54]])
A*V
#Output:-Matrix([
[ 29],
[ 65],
[101]])
A**3
#Output:-Matrix([
[ 468, 576, 684],
[1062, 1305, 1548],
[1656, 2034, 2412]])
B*A
#Output:-Matrix([
[ 7, 14, 21],
[ 42, 45, 48],
[-31, -32, -33]])
B.inv()*A*B
#Output:-Matrix([
[ 4/29, -437/29, 180/29],
[-28/29, 449/29, -216/29],
[-12/29, 6/29, -18/29]])
Q.6 Find inverse of matrix.
from sympy import*
A=Matrix([[2,1,1],[1,2,1],[1,1,2]])
B=Matrix([[1,1,1],[0,1,1],[0,0,1]])
A.inv()
#Output:-Matrix([
[ 3/4, -1/4, -1/4],
[-1/4, 3/4, -1/4],
[-1/4, -1/4, 3/4]])
B.inv()
#Output:-Matrix([
[1, -1, 0],
[0, 1, -1],
[0, 0, 1]])
Q.7 Print
i) 1st row of A & 2nd row of B
ii) 2nd column of A & 1st column of A
from sympy import*
A=Matrix([[2,1,1],[1,2,1],[1,1,2]])
B=Matrix([[1,1,1],[0,1,1],[0,0,1]])
A.row(0)
#Output:-Matrix([[2, 1, 1]])
B.row(2)
#Output:-Matrix([[0, 0, 1]])
A.col(1)
#Output:-Matrix([
[1],
[2],
[1]])
print(A)
#Output:-Matrix([[2, 1, 1], [1, 2, 1], [1, 1, 2]])
Matrix([[2, 1, 1], [1, 2, 1], [1, 1, 2]])
#Output:-Matrix([
[2, 1, 1],
[1, 2, 1],
[1, 1, 2]])
A.col(-2)
#Output:-Matrix([
[1],
[2],
[1]])
A.col_del(-1)
Print(A)
Output:-Matrix([
[2, 1],
[1, 1]])