Advertisement
lutunovoleg

Untitled

Jun 3rd, 2024
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.96 KB | Source Code | 0 0
  1. import IPython.display
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. import pandas as pd
  5. import math
  6. from IPython import display
  7. from docx import Document
  8. from docx.shared import Inches
  9.  
  10. data9_1 = [[1, 0.9, 1.586], [0.818, 1, 1.442]]
  11. # data9_1 =[[1, 0.8, 1.586], [0.553, 1, 1.07]]
  12. x_1 = 1000 * data9_1[0][0] / data9_1[0][2]
  13. x_2 = 1000 * data9_1[1][1] / data9_1[1][2]
  14. L_1 = x_1 / (2 * math.pi)
  15. L_2 = x_2 / (2 * math.pi)
  16. x_m1 = 1000 * data9_1[0][1] / data9_1[0][2]
  17. x_m2 = 1000 * data9_1[1][0] / data9_1[1][2]
  18. M_1 = x_m1 / (2 * math.pi)
  19. M_2 = x_m2 / (2 * math.pi)
  20. #
  21. first = pd.DataFrame({"U1,V": [data9_1[0][0], data9_1[1][0]],
  22.                       "U2,V": [data9_1[0][1], data9_1[1][1]],
  23.                       "I,mA": [data9_1[0][2], data9_1[1][2]],
  24.                       "x_i,Om": [round(x_1, 2), round(x_2, 2)],
  25.                       "L_i,mH": [round(L_1, 2), round(L_2, 2)],
  26.                       "x_mi,Om": [round(x_m1, 2), round(x_m2, 2)],
  27.                       "|M|,mH": [round(M_1, 2), round(M_2, 2)]}
  28.                      )
  29. print(first)
  30. print(f"|M_ср|={(M_1 + M_2) / 2}", f"X_m_ср={(x_m1 + x_m2) / 2}")
  31. print(f"k_1={M_1/pow(L_1*L_2,1/2)}\nk_2={M_2/pow(L_1*L_2,1/2)}")
  32. data9_2 = [[1, 0.487, 0.513, 0.407], [1, 0.336, 0.665, 5.272]]
  33. # data9_2 = [[1,    0.465,  0.535,  0.369], [1, 0.364, 0.636, 1.441]]
  34. # data9_2=[[1, 0.223, 0.771, 1.761], [1, 0.439, 0.561, 0.387]]
  35. x_mean = (x_m1 + x_m2) / 2
  36. M_mean = (M_1 + M_2) / 2
  37.  
  38. L_eq1 = L_1 + L_2 - 2 * M_mean
  39. L_eq2 = L_1 + L_2 + 2 * M_mean
  40. x_eq1 = math.pi * 2 * L_eq1
  41. x_eq2 = math.pi * 2 * L_eq2
  42. I_th1 = 1000 * data9_2[0][0] / x_eq1
  43. U_11 = I_th1 * (x_1 - x_mean) / 1000
  44. U_21 = I_th1 * (x_2 - x_mean) / 1000
  45.  
  46. I_th2 = 1000 * data9_2[1][0] / x_eq2
  47. U_12 = I_th2 * (x_1 + x_mean) / 1000
  48. U_22 = I_th2 * (x_2 + x_mean) / 1000
  49. print("\n\n")
  50. second = pd.DataFrame({"U,V": [data9_2[0][0], data9_2[1][0]],
  51.                        "U1,V": [data9_2[0][1], data9_2[1][1]],
  52.                        "U2,V": [data9_2[0][2], data9_2[1][2]],
  53.                        "I,mA": [data9_2[0][3], data9_2[1][3]],
  54.                        "I_th,mA": [I_th1, I_th2],
  55.                        "U1_th,V": [U_11, U_12],
  56.                        "U2_th,V": [U_21, U_22],
  57.                        "L_eq,mH": [L_eq1, L_eq2]})
  58. print(second)
  59. print(f"x_1={x_eq2}", f"x_2={x_eq1}")
  60. data9_3 = [[1, 1.641], [1, 21]]
  61. L_sog = (L_1 * L_2 - M_mean * M_mean) / (L_1 + L_2 - 2 * M_mean)
  62. I_sog = data9_3[0][0] / (2 * math.pi * L_sog)
  63. L_vst = (L_1 * L_2 - M_mean * M_mean) / (L_1 + L_2 + 2 * M_mean)
  64. I_vst = data9_3[0][0] / (2 * math.pi * L_vst)
  65. third = pd.DataFrame({"U": [data9_3[0][0], data9_3[1][0]],
  66.                       "I": [data9_3[0][1], data9_3[1][1]],
  67.                       "I_th": [I_sog * 1000, I_vst * 1000],
  68.                       "L_экв": [L_sog, L_vst]})
  69. print("\n", third)
  70.  
  71. R_1 = 1000
  72. R_2 = 220
  73.  
  74. t = [90, 70, 60, 40, 30, 10]
  75. A = 0.82
  76. print([A * t[i] / 100 for i in range(len(t))])
  77.  
  78.  
  79. def frequency_response(M, R, L_1, L_2, f):
  80.     w = 2 * np.pi * f
  81.     num = abs(M) * R
  82.     first = pow((L_1 * L_2 - M * M) * pow(10, -6), 2)
  83.     second = pow((L_1 * R) * pow(10, -3) / w, 2)
  84.     den = w * pow(first + second, 0.5)
  85.     return num / den / 1000
  86.  
  87. document = Document()
  88. table1 = document.add_table(rows=2, cols=8)
  89. table1.cell(0,0).text = "1"
  90. table1.cell(0,1).text = str(data9_1[0][0])
  91. table1.cell(0,2).text = str(data9_1[0][1])
  92. table1.cell(0,3).text = str(data9_1[0][2])
  93. table1.cell(0,4).text = str(round(x_1, 2))
  94. table1.cell(0,5).text = str(round(L_1, 2))
  95. table1.cell(0,6).text = str(round(x_m1,2))
  96. table1.cell(0,7).text = str(round(M_1,2))
  97. table1.cell(1,0).text = "2"
  98. table1.cell(1,1).text = str(data9_1[1][0])
  99. table1.cell(1,2).text = str(data9_1[1][1])
  100. table1.cell(1,3).text = str(data9_1[1][2])
  101. table1.cell(1,4).text = str(round(x_2, 2))
  102. table1.cell(1,5).text = str(round(L_2, 2))
  103. table1.cell(1,6).text = str(round(x_m2,2))
  104. table1.cell(1,7).text = str(round(M_2,2))
  105. table1.style = "Table Grid"
  106.  
  107. frequency = [1.588, 4.886, 6.8, 11.54, 15.033, 33.23, 294.374, 2786, 5765, 7509, 12743, 17734, 54566]
  108. exp =       [0.088, 0.261, 0.350, 0.521, 0.609, 0.798, 0.882, 0.791, 0.615, 0.528, 0.355, 0.266, 0.09]
  109. th = [frequency_response(M_mean, R_1, L_1, L_2, frequency[i]) for i in range(len(frequency))]
  110.  
  111.  
  112. table = document.add_table(rows=14, cols=6)
  113. for i in range(13):
  114.     table.cell(i+1, 0).text = str(round(frequency[i],3))
  115.     table.cell(i+1, 1).text = str(round(exp[i],3))
  116.     table.cell(i+1, 2).text = str(round(th[i],3))
  117. table.style = "Table Grid"
  118. table.cell(0, 0).text = "frequency"
  119. table.cell(0, 1).text = "exp"
  120. table.cell(0, 2).text = "th"
  121.  
  122. # Строим график с двумя кривыми
  123. data1 = pd.DataFrame({"frequency": frequency, "exp": exp, "th": th})
  124. # IPython.display.display(data1)
  125. # print(data1)
  126. plt.figure(figsize=(10, 6))
  127. plt.plot(frequency, exp, label="exp", linestyle='-', )
  128. plt.plot(frequency, th, label="th", linestyle='-.', )
  129. plt.xscale("log", base=2)
  130. plt.xlabel("Частота (Гц)")
  131. plt.ylabel("АЧХ R=1000")
  132. plt.legend()
  133. plt.show()
  134. frequency = [1.487, 4.886, 6.8, 11.54, 15.033, 29.115, 142.269, 695, 1345, 1754, 2976, 4142, 12743]
  135. exp =       [0.080, 0.252, 0.336, 0.499, 0.581, 0.735, 0.822, 0.733, 0.579, 0.496, 0.334, 0.250, 0.085]
  136. th = [frequency_response(M_mean, R_2, L_1, L_2, frequency[i]) for i in range(len(frequency))]
  137. data2 = pd.DataFrame({"frequency": frequency, "exp": exp, "th": th})
  138. # print(data2)
  139.  
  140. # IPython.display.display(data2)
  141.  
  142. plt.figure(figsize=(10, 6))
  143. plt.plot(frequency, exp, label="exp", linestyle='-', )
  144. plt.plot(frequency, th, label="th", linestyle='-.', )
  145. plt.xscale("log", base=2)
  146. plt.xlabel("Частота (Гц)")
  147. plt.ylabel("АЧХ R=220")
  148. plt.legend()
  149. plt.show()
  150. for i in range(13):
  151.     table.cell(i+1, 3).text = str(round(frequency[i],3))
  152.     table.cell(i+1, 4).text = str(round(exp[i],3))
  153.     table.cell(i+1, 5).text = str(round(th[i],3))
  154.  
  155. table.cell(0, 3).text = "frequency"
  156. table.cell(0, 4).text = "exp"
  157. table.cell(0, 5).text = "th"
  158. document.save("document.docx")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement