-
Notifications
You must be signed in to change notification settings - Fork 0
/
newadjoint.py
146 lines (110 loc) · 3.27 KB
/
newadjoint.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import numpy as np
while True:
class adjmatr():
print("\t\t\033[33m.....we support only 3x3 matrix....\033[0m")
print("\n\033[36m Mod of Your Matrix : 1\033[0m")
print("\n\033[36m Adjoint of Your Matrix : 2 \033[0m")
print("\n\033[36m Inverse of Your Matrix : 3 \033[0m")
print('')
print("\n But First type your 3x3 matrix as bellow : \n")
tfg=np.array(['A','B','C','D','E','F','G','H','I'])
MAJ=tfg.reshape(3,3)
print(MAJ)
global A
global B
global C
global D
global E
global F
global G
global H
global I
A=int(input("\033[32mA : "))
B=int(input("B : "))
C=int(input("C : "))
D=int(input("D : "))
E=int(input("E : "))
F=int(input("F : "))
G=int(input("G : "))
H=int(input("H : "))
I=int(input("I : "))
print("\033[0m")
#AA=int(input("AA : "))
#XX=int(input("KK : "))
ar=np.array([A,B,C,D,E,F,G,H,I])
ar1=ar.reshape(3,3)
#print(" your matrix look like : \t")
print("\033[33m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\033[0m")
print("\033[33mLet , your matrix be 'A' \033[0m" )
print(" A = ")
print("\n\033[33m",ar1,"\033[0m")
print("")
print("\033[33m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\033[0m")
def modof():
global mod
mod=(+(A*((E*I)-(F*H)))-(B*((D*I)-(F*G)))+(C*((D*H)-(G*E))))
print('')
print("\033[32m the |A| = \033[0m","\033[36m",mod,"\033[0m")
print('')
def cofac():
AA=+((E*I)-(F*H))
BB=-((D*I)-(F*G))
CC=+((D*H)-(G*E))
DD=-((B*I)-(C*H))
EE=+((A*I)-(C*G))
FF=-((A*H)-(B*G))
GG=+((B*F)-(C*E))
HH=-((A*F)-(C*D))
II=+((A*E)-(B*D))
arr=np.array([AA,BB,CC,DD,EE,FF,GG,HH,II])
ar2=arr.reshape(3,3)
global adjmain
adjmain=ar2.transpose()
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
#print("\t",mod)
print('')
print("\033[35m Let, 'D' is the matrix with the CO-factor of |A| \033[0m ")
print("\033[31m D = \033[0m")
print('')
print(ar2)
print("")
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
print("\033[33mSo the adjoint of your matrix(A) [adjA] : \033[0m")
print("\n",adjmain)
print("\033[33m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\033[0m")
def ainverse():
mod=(+(A*((E*I)-(F*H)))-(B*((D*I)-(F*G)))+(C*((D*H)-(G*E))))
AA=+((E*I)-(F*H))
BB=-((D*I)-(F*G))
CC=+((D*H)-(G*E))
DD=-((B*I)-(C*H))
EE=+((A*I)-(C*G))
FF=-((A*H)-(B*G))
GG=+((B*F)-(C*E))
HH=-((A*F)-(C*D))
II=+((A*E)-(B*D))
arr=np.array([AA,BB,CC,DD,EE,FF,GG,HH,II])
ar2=arr.reshape(3,3)
global adjmain
adjmain=ar2.transpose()
print(" \033[33mNow the A`¹ {A inverse} = \n\033[0m")
gun=(1/mod)*(adjmain)
print("")
print("\033[33m\n1/%d"%mod,"x\n",adjmain)
print("\nor,")
print(gun)
print("")
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\033[0m")
#invrs=input("Do you want to multiply any matrix with A`¹ {A inverse} [y/n] : ")
for i in range(0,3):
#
print("Now Enter Your choice : ")
first=input("\033[36m choice@\033[0m : ")
if first=="1":
modof()
if first=="2":
cofac()
if first=="3":
ainverse()
#fgh=input("again [y/n]: ")
#if fgh=="y":