1
+ ##For A[] * x[] = B[] with Delta Division for 3 unkwnowns
2
+ #Displayable Matrix results to display what's going on step by step
3
+ #Utilizing Array self as the instance as it applies Matrix B column by column into
4
+ #Matrix A, giving us Delta Delta 1, 2, 3
5
+ import numpy as np
6
+
7
+ class array_from_user : # main matrix class
8
+ def __init__ (ArraySelf , r1_c1 , r1_c2 , r1_c3 ,#First Array Initializer
9
+ r2_c1 , r2_c2 , r2_c3 ,
10
+ r3_c1 , r3_c2 , r3_c3 ,
11
+
12
+ second_1 , second_2 , second_3 ):#Second Array Initializer
13
+
14
+ ArraySelf .original_array = np .array ([[r1_c1 , r1_c2 , r1_c3 ],
15
+ [r2_c1 , r2_c2 , r2_c3 ],
16
+ [r3_c1 , r3_c2 , r3_c3 ]])
17
+
18
+ ArraySelf .delta1_array = np .array ([[second_1 , r1_c2 , r1_c3 ],
19
+ [second_2 , r2_c2 , r2_c3 ],
20
+ [second_3 , r3_c2 ,r3_c3 ]])
21
+
22
+ ArraySelf .delta2_array = np .array ([[r1_c1 , second_1 , r1_c3 ],
23
+ [r2_c1 , second_2 , r2_c3 ],
24
+ [r3_c1 , second_3 , r3_c3 ]])
25
+
26
+ ArraySelf .delta3_array = np .array ([[r1_c1 , r1_c2 , second_1 ],
27
+ [r2_c1 , r2_c2 , second_2 ],
28
+ [r3_c1 , r3_c2 , second_3 ]])
29
+
30
+ #These variables are to add readability to the rest of the code, they are the Determinants
31
+ DeterOrigin = np .linalg .det (ArraySelf .original_array )
32
+ DeterD1 = np .linalg .det (ArraySelf .delta1_array )
33
+ DeterD2 = np .linalg .det (ArraySelf .delta2_array )
34
+ DeterD3 = np .linalg .det (ArraySelf .delta3_array )
35
+
36
+ #Print all values to the user upon current
37
+ print ('Cramers Law step by step!\n Utilizing A [] X[] = B[] for the unknown\n ' )
38
+ print ('\n Delta Array:' , ArraySelf .original_array ,'\n Determinant:' , DeterOrigin )
39
+
40
+ print ('\n Delta 1:\n ' ,ArraySelf .delta1_array , 'Determinant:' , DeterD1 )
41
+ print ('\n Delta 2:\n ' ,ArraySelf .delta2_array , 'Determinant:' , DeterD2 )
42
+ print ('\n Delta 3:\n ' ,ArraySelf .delta3_array , 'Determinant:' ,DeterD3 )
43
+
44
+ #Defining final unknowns or x in A[]x[]=B[]
45
+
46
+ unknown1 = round ( (DeterD1 / DeterOrigin ), 2 )
47
+ print ('\n Delta 1 / Delta =' , unknown1 )
48
+ unknown2 = round ((DeterD2 / DeterOrigin ), 2 )
49
+ print ('\n Delta 2 / Delta =' , unknown2 )
50
+ unknown3 = round (DeterD3 / DeterOrigin ), 2 )
51
+ print ('\n Delta 3 / Delta =' , unknown3 )
52
+
53
+ #main code, this simply displays the code via its initializer
54
+ #the final 3 values are for the known solutions for cramers
55
+ # the first 9 digits are to fill a 3 x 3 matrix
56
+ user_array = array_from_user (20 , 30 , 15 , #First Array
57
+ 17 , 45 , 66 ,
58
+ 17 , 28 , 59 ,
59
+
60
+ 21 , 22 , 23 ) #Second Array
0 commit comments