0% found this document useful (0 votes)
15 views13 pages

Ilovepdf Merged

egew4g4wg43wg

Uploaded by

hassanmansuri570
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views13 pages

Ilovepdf Merged

egew4g4wg43wg

Uploaded by

hassanmansuri570
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

3/22/24, 2:45 PM 2024-03-16-file-1 (2).

html

Kernel: SageMath 10.2

In [0]:

Practical 7
Name - Harshvardhan Singh

Roll no - 15

In [1]: show(matrix(ZZ,3,2,[1,2,3,4,5,6]))

Out[1]: 1 2
​ 3 ​ 4 ​ ​

5 6

In [2]:
P= matrix(2,3,[8,5,6,9,7,3])
Q= matrix(2,3,[1,2,5,3,6,4])
show('P+Q= ',P+Q)
show('P-Q= ',P-Q)

Out[2]: 9 7 11
P+Q= ( ​ ​
)​

12 13 7

7 3 1
P-Q= ( ​ ​ )​
6 1 −1

In [3]: show(Q.transpose())

file:///C:/Users/ASUS/Downloads/2024-03-16-file-1 (2).html 1/8


3/22/24, 2:45 PM 2024-03-16-file-1 (2).html

Out[3]: 1 3
​ 2 ​ 6 ​ ​

5 4

In [4]:
show(P.transpose()*Q)

Out[4]: 35 70 76
​ 26 ​ 52 ​ 53 ​ ​

15 30 42

In [5]: R=matrix(2,2,[-8,5,1,-7])
show('R=',R,'R^5=',R^5)

Out[5]: −8 5 −56313 94005


R= ( ​
) R^5= (
​ ​ ​
)
1 −7 18801 −37512

In [6]:
show(R.det())

Out[6]: 51

In [7]:
show(R.transpose())

Out[7]: −8 1
( ​ ) ​
5 −7

In [8]: R.inverse()

Out[8]: [-7/51 -5/51]


[-1/51 -8/51]

In [11]:
R.trace()

Out[11]: -15

file:///C:/Users/ASUS/Downloads/2024-03-16-file-1 (2).html 2/8


3/22/24, 2:45 PM 2024-03-16-file-1 (2).html

In [10]: R.adjugate()

Out[10]: [-7 -5]


[-1 -8]

In [12]: R.trace()

Out[12]: -15

In [13]: 3*R

Out[13]: [-24 15]


[ 3 -21]

In [14]: var('x,y')
S=matrix(3,3,[x+y,x,x,5*x+4*y,4*x,2*x,10*x+8*y,8*x,3*x])
show('S=',S)

Out[14]: x+y x x
S= ​ 5x + 4y ​ 4x ​ 2x ​ ​

10 x + 8 y 8x 3x

In [15]: show('|S|=',S.det())

Out[15]: |S|=(5 x + 4 y )x2 − 4 (x + y )x2

In [16]: T= S.det()
T.full_simplify()

Out[16]: x^3

In [17]: show(diff(S,x))
show(diff(S,y))

file:///C:/Users/ASUS/Downloads/2024-03-16-file-1 (2).html 3/8


3/22/24, 2:45 PM 2024-03-16-file-1 (2).html

Out[17]: 1 1 1
​ 5 ​ 4 ​ 2 ​ ​

10 8 3

1 0 0
​ 4 ​ 0 ​ 0 ​ ​

8 0 0

In [18]: S.minors(1)

Out[18]: [x + y, x, x, 5*x + 4*y, 4*x, 2*x, 10*x + 8*y, 8*x, 3*x]

In [19]: S.minors(2)

Out[19]: [-(5*x + 4*y)*x + 4*(x + y)*x,


-(5*x + 4*y)*x + 2*(x + y)*x,
-2*x^2,
-2*(5*x + 4*y)*x + 8*(x + y)*x,
-2*(5*x + 4*y)*x + 3*(x + y)*x,
-5*x^2,
0,
-(5*x + 4*y)*x,
-4*x^2]

In [20]:
S.minors(3)

Out[20]: [(5*x + 4*y)*x^2 - 4*(x + y)*x^2]

In [21]:
S.minors(3)==[S.det()]

Out[21]: True

In [22]:
X=ones_matrix(5,6)
show('X=',X)

file:///C:/Users/ASUS/Downloads/2024-03-16-file-1 (2).html 4/8


3/22/24, 2:45 PM 2024-03-16-file-1 (2).html

Out[22]: 1 1 1 1 1 1
1 1 1 1 1 1
X= ​ 1 ​ 1 ​ 1 ​ 1 ​ 1 ​ 1 ​ ​

1 1 1 1 1 1
1 1 1 1 1 1

In [23]:
X[1:3,0:2]=10
show(X)

Out[23]: 1 1 1 1 1 1
10 10 1 1 1 1
​ 10 ​ 10 ​ 1 ​ 1 ​ 1 ​ 1 ​ ​

1 1 1 1 1 1
1 1 1 1 1 1

In [24]: X[1:3]=10
show(X)

Out[24]: 1 1 1 1 1 1
10 10 10 10 10 10
​ 10 ​ 10 ​ 10 ​ 10 ​ 10 ​ 10 ​ ​

1 1 1 1 1 1
1 1 1 1 1 1

In [25]: # System opf equation

In [26]:
T= matrix(3,3,[1,2,3,4,5,6,7,8,9])
show(T)

file:///C:/Users/ASUS/Downloads/2024-03-16-file-1 (2).html 5/8


3/22/24, 2:45 PM 2024-03-16-file-1 (2).html

Out[26]: 1 2 3
​ 4 ​ 5 ​ 6 ​ ​

7 8 9

In [32]:
T[0]

Out[32]: (1, 2, 3)

In [33]:
T[1]

Out[33]: (4, 5, 6)

In [34]:
T[2]

Out[34]: (7, 8, 9)

In [35]:
T[1,0]

Out[35]: 4

In [31]:
T[2,1]

Out[31]: 8

In [36]:
T[1]*T[2]

Out[36]: 122

In [38]: show(T * T)

Out[38]: 30 36 42
​ 66 ​ 81 ​ 96 ​ ​

102 126 150

file:///C:/Users/ASUS/Downloads/2024-03-16-file-1 (2).html 6/8


3/22/24, 2:45 PM 2024-03-16-file-1 (2).html

In [61]: x,y,z = var('x,y,z')


solve = ([x-2*y+3*z == 2 , 2*x-3*z ==3,x+y+z == 0] , x,y,z)

In [46]: A = matrix([[1,-2,3],[2,0,-3],[1,1,1]])
B = vector([2,3,0])
show( 'A =' ,A , 'B= ', B.column())

Out[46]: 1 −2 3 2
A = ​ 2 ​ 0 ​ −3 ​ ​ B= ​ 3 ​ ​

1 1 1 0

In [45]:
C = A.augment(B)

C
show('C :' , C)

Out[45]: 1 −2 3 2
C : ​ 2 ​ 0 ​ −3 ​ 3 ​ ​

1 1 1 0

In [47]:
rank(C)

Out[47]: 3

In [48]:
rank(A)

Out[48]: 3

In [49]:
C.echelon_form()

Out[49]: [ 1 0 8 -1]
[ 0 1 12 -4]
[ 0 0 19 -5]

In [0]:

file:///C:/Users/ASUS/Downloads/2024-03-16-file-1 (2).html 7/8


3/22/24, 2:45 PM 2024-03-16-file-1 (2).html

In [53]: # Linearly dependent

In [62]: U = matrix(3,4,[1,-1,2,4,-3,3,2,1,-1,-2,6,9])

In [1]: x,y,z = var('x,y,z')


solve([x-y+2*z==4 , -3*x+3*y+2*x== 1, -1*x-2*y+6*z==9] , x, y, z)

Out[1]: [[x == (10/11), y == (7/11), z == (41/22)]]

In [0]:

In [0]:

file:///C:/Users/ASUS/Downloads/2024-03-16-file-1 (2).html 8/8


3/22/24, 2:36 PM 2024-03-22-file-1.html

Kernel: SageMath 10.2

In [0]:

Exercise Questions
Name - Harshvardhan Singh

Roll ni - B1-15

In [1]: #Q1

In [3]: var('x,y,z,t')
A = matrix(2,2,[x,y,z,t])
show('A= ', A)

Out[3]:
A= ( )
x ​
y​

z t

In [4]:
B = matrix(2,2,[1,-1,0,0])
show('B= ', B)

Out[4]: 1 −1
B= ( ​ ) ​

0 0

In [7]: C = matrix(2,2,[3,5,4,6])
show('C = ', C)

file:///C:/Users/ASUS/Downloads/2024-03-22-file-1.html 1/5
3/22/24, 2:36 PM 2024-03-22-file-1.html

Out[7]: 3 5
C =( ​ ​)
4 6

In [9]:
equation = 2*A + 3*B -3*C
solution = solve(equation.list(), [x,y,z,t])
show(solution)

Out[9]: [[x = 3, y = 9, z = 6, t = 9]]

In [10]:
#Q2

In [11]: A = matrix(3,3,[1,2,3,1,3,3,1,2,4])
B = matrix(3,3,[5,2,3,7,3,4,9,4,5])
show('A =', A , 'B = ' , B)

Out[11]: 1 2 3 5 2 3
A = ​ 1 ​ 3 ​ 3 ​ ​ B = ​ 7 ​ 3 ​ 4 ​ ​

1 2 4 9 4 5

In [12]:
show(A.determinant())

Out[12]: 1

In [13]: show(B.determinant())

Out[13]: 0

In [17]:
show('A Adjoint = ',A.adjugate())
show('B Adjoint =', B.adjugate())

file:///C:/Users/ASUS/Downloads/2024-03-22-file-1.html 2/5
3/22/24, 2:36 PM 2024-03-22-file-1.html

Out[17]: 6 −2 −3
A Adjoint = ​ −1 ​ 1 ​ 0 ​ ​

−1 0 1

−1 2 −1
B Adjoint = ​ 1 ​ −2 ​ 1 ​ ​

1 −2 1

In [21]: show('A Inverse = ',A.inverse())


show('B Inverse = Non Singular Hence No Inverse' )

Out[21]: 6 −2 −3
A Inverse = ​ −1 ​ 1 ​ 0 ​ ​

−1 0 1

B Inverse = Non Singular Hence No Inverse

In [27]:
show('1 = ', A.minors(1))
show('2 =' ,A.minors(2))
show('3 =',A.minors(3))

Out[27]: 1 = [1, 2, 3, 1, 3, 3, 1, 2, 4]

2 = [1, 0, −3, 0, 1, 2, −1, 1, 6]

3 = [1 ]

In [28]: show('1 = ', B.minors(1))


show('2 =' ,B.minors(2))
show('3 =',B.minors(3))

Out[28]: 1 = [5, 2, 3, 7, 3, 4, 9, 4, 5]

2 = [1, −1, −1, 2, −2, −2, 1, −1, −1]

3 = [0 ]

file:///C:/Users/ASUS/Downloads/2024-03-22-file-1.html 3/5
3/22/24, 2:36 PM 2024-03-22-file-1.html

In [35]: show('A+B =', A+B)


show('_')

show('A-B =', A-B)


show('_')
show('AB =', A*B)
show('_')
show('A^6 =', A^6)

Out[35]: 6 4 6
A+B = ​ 8 ​ 6 ​ 7 ​ ​

10 6 9

−4 0 0
A-B = ​ −6 ​ 0 ​ −1 ​ ​

−8 −2 −1

46 20 26
AB = ​ 53 ​ 23 ​ 30 ​ ​

55 24 31

13201 30912 46368


A^6 = ​ 15456 ​ 36193 ​ 54288 ​ ​

15456 36192 54289

In [36]: #Q3

In [40]:
var('x,y,z')
show(solve([3*x+y+z==2, x-3*y+2*z==1, 7*x - y+4*z==5],x,y,z))

Out[40]: 1 7 1 1
[[x = − r1 + , y = r1 − , z = r1 ]]
​ ​ ​ ​ ​ ​ ​

2 10 2 10

file:///C:/Users/ASUS/Downloads/2024-03-22-file-1.html 4/5
3/22/24, 2:36 PM 2024-03-22-file-1.html

In [43]: X = matrix(3,3,[3,1,1,1,-3,2,7,-1,4])
Y = vector([2,1,5])
show('X =', X, 'Y =', Y)

Out[43]: 3 1 1
X = ​ 1 ​ −3 ​ 2 ​ ​ Y = (2, 1, 5)
7 −1 4

In [47]:
Z = X.augment(Y)
show('Z =',Z)

Out[47]: 3 1 1 2
Z = ​ 1 ​ −3 ​ 2 ​ 1 ​ ​

7 −1 4 5

In [48]:
rank(X)

Out[48]: 2

In [50]: rank(Z)

Out[50]: 2

In [51]:
show(rank(X)== rank(Z))

Out[51]: True

In [52]: show(Z.echelon_form())

Out[52]: 1 7 −3 0
​ 0 ​ 10 ​ −5 ​ −1 ​ ​

0 0 0 0

In [0]:

file:///C:/Users/ASUS/Downloads/2024-03-22-file-1.html 5/5

You might also like