Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 3

Python Programming Language I

Practical 6 : Determinants

Q.1) For the matrix


[6 18 3 −7] [√2 0 0 0]
A= [2 12 1 8],B= [-8 √(2) 0 0]
[4 15 3 9] [7 0 -1 0]
[−1 3 5 10] [9 5 6 1]
Find

Code:
>>> from sympy import *
>>> A=Matrix([[6,18,13,-7],[2,12,1,8],[4,15,3,9],[-1,3,5,10]])
>>> A
Matrix([
[ 6, 18, 13, -7],
[ 2, 12, 1, 8],
[ 4, 15, 3, 9],
[-1, 3, 5, 10]])

>>> B=Matrix([[cmath.sqrt(2),0,0,0],[-8,cmath.sqrt(2),0,0],[7,0,-1,0],
[9,5,6,1]])
>>> B
Matrix([
[1.4142135623731, 0, 0, 0],
[-8, 1.4142135623731, 0, 0],
[ 7, 0, -1, 0],
[ 9, 5, 6, 1]])
>>> C=A+B

a)Determinant Of And B
Code:
>>> A.det()
-2997
>>> B.det()
-2.00000000000000

b)Determinant Of A+B
>>> C=A+B
>>> C
Matrix([
[7.41421356237309, 18, 13, -7],
[-6, 13.4142135623731, 1, 8],
[ 11, 15, 2, 9],
[ 8, 8, 11, 11]])

c)Determinant Of AB And CommentOn Your Answer


>>> P=A*B
>>> P
Matrix([
[-107.514718625761, -9.54415587728429, -55, -7],
[-14.1715728752538, 56.9705627484771, 47, 8],
[-12.3431457505076, 66.2132034355964, 51, 9],
[ 99.5857864376269, 54.2426406871193, 55, 10]])
>>> P.det()
5994.00000000033

d)Determinant Of A^2-B^2
>>> X=A**2
>>> X
Matrix([
[131, 498, 100, 149],
[ 32, 219, 81, 171],
[ 57, 324, 121, 209],
[ 10, 123, 55, 176]])
>>> Y=B**2
>>> Y
Matrix([
[ 2.0, 0, 0, 0],
[-22.6274169979695, 2.0, 0, 0],
[ 2.89949493661167, 0, 1, 0],
[ 23.7279220613579, 12.0710678118655, 0, 1]])
>>> Z=X-Y
>>> Z
Matrix([
[ 129.0, 498, 100, 149],
[ 54.6274169979695, 217.0, 81, 171],
[ 54.1005050633883, 324, 120, 209],
[-13.7279220613579, 110.928932188135, 55, 175]])
>>> Z.det()
-58569018.9198429

e)Determinant Of -2A+3B
>>> U=-2*A
>>> U
Matrix([
[-12, -36, -26, 14],
[ -4, -24, -2, -16],
[ -8, -30, -6, -18],
[ 2, -6, -10, -20]])
>>> V=3*B
>>> V
Matrix([
[4.24264068711929, 0, 0, 0],
[ -24, 4.24264068711929, 0, 0],
[ 21, 0, -3, 0],
[ 27, 15, 18, 3]])
>>> W=U+V
>>> W
Matrix([
[-7.75735931288071, -36, -26, 14],
[ -28, -19.7573593128807, -2, -16],
[ 13, -30, -9, -18],
[ 29, 9, 8, -17]])

You might also like