|
| 1 | +import numpy as np |
| 2 | + |
| 3 | +mat1 = [[1, 1], [2, 2]] |
| 4 | +mat2 = [[1, 1], [1, 2]] |
| 5 | + |
| 6 | +first_frac = mat1[0][0] / mat1[1][0] |
| 7 | +second_frac = mat1[0][1] / mat1[1][1] |
| 8 | + |
| 9 | +print(first_frac, second_frac) |
| 10 | + |
| 11 | +twofirst = mat2[0][0] / mat2[1][0] |
| 12 | +twosecond = mat2[0][1] / mat2[1][1] |
| 13 | + |
| 14 | +print(twofirst, twosecond) |
| 15 | + |
| 16 | +ff1 = mat1[0][0] * mat1[1][1] |
| 17 | +ff2 = mat1[0][1] * mat1[1][0] |
| 18 | + |
| 19 | +print(ff1, ff2, ff1 - ff2) |
| 20 | + |
| 21 | +ff11 = mat2[0][0] * mat2[1][1] |
| 22 | +ff22 = mat2[1][0] * mat2[0][1] |
| 23 | + |
| 24 | +print(ff11, ff22, ff11 - ff22) |
| 25 | + |
| 26 | + |
| 27 | +mat3 = [[5, 1], [-1, 3]] |
| 28 | + |
| 29 | + |
| 30 | +first3 = mat3[0][0] * mat3[1][1] |
| 31 | +second3 = mat3[0][1] * mat3[1][0] |
| 32 | + |
| 33 | +print(first3, second3, first3 - second3) ## singular |
| 34 | + |
| 35 | +mat4 = [[2, -1], [-6, 3]] |
| 36 | + |
| 37 | +first4 = mat4[0][0] * mat4[1][1] |
| 38 | +second4 = mat4[0][1] * mat4[1][0] |
| 39 | + |
| 40 | +print(first4, second4, first4 - second4) |
| 41 | + |
| 42 | +mat5 = [[2, 3], [2, 4]] |
| 43 | + |
| 44 | +first5 = mat5[0][0] * mat5[1][1] |
| 45 | +second5 = mat5[0][1] * mat5[1][0] |
| 46 | + |
| 47 | +print(first5, second5, first5 - second5) |
| 48 | + |
| 49 | +mat1 = [[1, 0, 1], [0, 1, 0], [3, 3, 3]] |
| 50 | + |
| 51 | +dt_1_first_diag = mat1[0][0] * mat1[1][1] * mat1[2][2] |
| 52 | +dt_1_second_diag = mat1[0][1] * mat1[1][2] * mat1[2][0] |
| 53 | +dt_1_third_diag = mat1[0][2] * mat1[1][0] * mat1[2][1] |
| 54 | + |
| 55 | +dt_1_anti_first_diag = mat1[0][2] * mat1[1][1] * mat1[2][0] |
| 56 | +dt_1_anti_second_diag = mat1[0][1] * mat1[1][0] * mat1[2][2] |
| 57 | +dt_1_anti_third_diag = mat1[0][0] * mat1[1][2] * mat1[2][1] |
| 58 | + |
| 59 | +dt_1 = (dt_1_first_diag + dt_1_second_diag + dt_1_third_diag) - ( |
| 60 | + dt_1_anti_first_diag - dt_1_anti_second_diag - dt_1_anti_third_diag |
| 61 | +) |
| 62 | + |
| 63 | +print(dt_1) |
| 64 | + |
| 65 | + |
| 66 | +mat2 = [[1, 1, 1], [1, 1, 2], [0, 0, -1]] |
| 67 | + |
| 68 | + |
| 69 | +dt_2_first_diag = mat2[0][0] * mat2[1][1] * mat2[2][2] |
| 70 | +dt_2_second_diag = mat2[0][1] * mat2[1][2] * mat2[2][0] |
| 71 | +dt_2_third_diag = mat2[0][2] * mat2[1][0] * mat2[2][1] |
| 72 | + |
| 73 | +dt_2_anti_first_diag = mat2[0][2] * mat2[1][1] * mat2[2][0] |
| 74 | +dt_2_anti_second_diag = mat2[0][1] * mat2[1][0] * mat2[2][2] |
| 75 | +dt_2_anti_third_diag = mat2[0][0] * mat2[1][2] * mat2[2][1] |
| 76 | + |
| 77 | +dt_2 = (dt_2_first_diag + dt_2_second_diag + dt_2_third_diag) + ( |
| 78 | + dt_2_anti_first_diag - dt_2_anti_second_diag - dt_2_anti_third_diag |
| 79 | +) |
| 80 | + |
| 81 | +print(dt_2) |
| 82 | + |
| 83 | + |
| 84 | +mat3 = [[1, 1, 1], [0, 2, 2], [0, 0, 3]] |
| 85 | + |
| 86 | +dt_3_first_diag = mat3[0][0] * mat3[1][1] * mat3[2][2] |
| 87 | +dt_3_second_diag = mat3[0][1] * mat3[1][2] * mat3[2][0] |
| 88 | +dt_3_third_diag = mat3[0][2] * mat3[1][0] * mat3[2][1] |
| 89 | + |
| 90 | +dt_3_anti_first_diag = mat3[0][2] * mat3[1][1] * mat3[2][0] |
| 91 | +dt_3_anti_second_diag = mat3[0][1] * mat3[1][0] * mat3[2][2] |
| 92 | +dt_3_anti_third_diag = mat3[0][0] * mat3[1][2] * mat3[2][1] |
| 93 | + |
| 94 | +dt_3_first = dt_3_first_diag + dt_3_second_diag + dt_3_third_diag |
| 95 | +dt_3_second = dt_3_anti_first_diag - dt_3_anti_second_diag - dt_3_anti_third_diag |
| 96 | + |
| 97 | +dt_3 = dt_3_first + dt_3_second |
| 98 | + |
| 99 | +print(dt_3) |
| 100 | + |
| 101 | +mat4 = [[1, 2, 5], [0, 3, -2], [2, 4, 10]] |
| 102 | + |
| 103 | +dt_4_first_diag = mat4[0][0] * mat4[1][1] * mat4[2][2] |
| 104 | +dt_4_second_diag = mat4[0][1] * mat4[1][2] * mat4[2][0] |
| 105 | +dt_4_third_diag = mat4[0][2] * mat4[1][0] * mat4[2][1] |
| 106 | + |
| 107 | +dt_4_anti_first_diag = mat4[0][2] * mat4[1][1] * mat4[2][0] |
| 108 | +dt_4_anti_second_diag = mat4[0][1] * mat4[1][0] * mat4[2][2] |
| 109 | +dt_4_anti_third_diag = mat4[0][0] * mat4[1][2] * mat4[2][1] |
| 110 | + |
| 111 | +print( |
| 112 | + "first = {} {} {} second = {} {} {}".format( |
| 113 | + dt_4_first_diag, |
| 114 | + dt_4_second_diag, |
| 115 | + dt_4_third_diag, |
| 116 | + dt_4_anti_first_diag, |
| 117 | + dt_4_anti_second_diag, |
| 118 | + dt_4_anti_third_diag, |
| 119 | + ) |
| 120 | +) |
| 121 | + |
| 122 | +dt_4_first = dt_4_first_diag + dt_4_second_diag + dt_4_third_diag |
| 123 | +dt_4_second = dt_4_anti_first_diag + dt_4_anti_second_diag + dt_4_anti_third_diag |
| 124 | + |
| 125 | +dt_4 = dt_4_first - dt_4_second |
| 126 | + |
| 127 | +print("dt4 = {}".format(dt_4)) |
0 commit comments