• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# lab2(CM) ver 0.0

allekco Nov 16th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. def f1(x, y, z):
2.     return 9*x*z**2 + y*z + 2*y**2*x**3 + 175
3. def f2(x, y, z):
4.     return 0.5*y**3*z**2 - 0.8*x**2*y - 5.5 + 4.2
5. def f3(x, y, z):
6.     return 0.7*z**3 - 6.3*y**3 - 12.6
7. def f1_der_x(x, y, z):     #derivative
8.     return 9*z**2 + 2*y**2*3*x**2
9. def f1_der_y(x, y, z):
10.     return z + 2*2*y*x**3
11. def f1_der_z(x, y, z):
12.     return 9*x*2*z + y
13. def f2_der_x(x, y, z):
14.     return -0.8*2*x*y
15. def f2_der_y(x, y, z):
16.     return 1.5*y**2 - 0.8*x**2
17. def f2_der_z(x, y, z):
18.     return y**3*z
19. def f3_der_x(x, y, z):
20.     return 0
21. def f3_der_y(x, y, z):
22.     return -18.9*y**2
23. def f3_der_z(x, y, z):
24.     return 2.1*z**2
25.
26.
27. def w_matrix(x, y, z):
28.     W = [[f1_der_x(x, y, z), f1_der_y(x, y, z), f1_der_z(x, y, z)],
29.          [f2_der_x(x, y, z), f2_der_y(x, y, z), f2_der_z(x, y, z)],
30.          [f3_der_x(x, y, z), f3_der_y(x, y, z), f3_der_z(x, y, z)]]
31.     return W
32.
33.
34. def def_matrix(a=[]):
35.     return (a[0][0]*a[1][1]*a[2][2] + a[2][0]*a[0][1]*a[1][2] +
36.             a[1][0]*a[2][1]*a[0][2] - a[2][0]*a[1][1]*a[0][2] -
37.             a[0][0]*a[2][1]*a[1][2] - a[1][0]*a[0][1]*a[2][2])
38.
39.
40. def t_matrix(a=[]):
41.     a1 = a[0][0]
42.     a2 = a[1][0]
43.     a3 = a[2][0]
44.     b1 = a[0][1]
45.     b2 = a[1][1]
46.     b3 = a[2][1]
47.     c1 = a[0][2]
48.     c2 = a[1][2]
49.     c3 = a[2][2]
50.     B = [[a1*b2-a2*b1, -a2*c3+a3*c2, a2*b3-a3*b2],
51.          [-b1*c3+b3*c1, a1*c3-a3*c1, -a1*b3+a3*b1],
52.          [b1*c2-b2*c1, -a1*c2+a2*c1, a1*b2-a2*b1]]
53.     return B
54.
55. def inverse_matrix(a=[]):
56.     T = t_matrix(a)
57.     q = def_matrix(a)
58.     if def_matrix(a) == 0:
59.         print("def_matrix = 0")
60.         return a
61.     for i in range(3):
62.         for k in range(3):
63.             a[i][k] = T[i][k]/q
64.     return a
65.
66.
67.
68. def output_matrix(a=[]):
69.     print(a[0][0], ' ', a[0][1], ' ', a[0][2])
70.     print(a[1][0], ' ', a[1][1], ' ', a[1][2])
71.     print(a[2][0], ' ', a[2][1], ' ', a[2][2])
72.     print('')
73.
74.
75.
76.
77. x = 1
78. y = 1
79. z = 1
80. W = w_matrix(1, 1, 1) #[номер строки][номер столбца]
81. W = [[2,1,1],[1,2,1],[1,1,2]]
82. output_matrix(W)
83. T = t_matrix(W)
84. output_matrix(T)
85. I = inverse_matrix(W)
86. output_matrix(I)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?