Advertisement
Guest User

Untitled

a guest
Feb 18th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.00 KB | None | 0 0
  1. import math
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4.  
  5. # определим константы
  6.  
  7. R = 4
  8. kk = 0.065
  9. alpha = 0.001
  10. T = [0, 15]
  11. c = 1.84
  12. e = 0.00001
  13. n = 100
  14. #gamma = alpha * R / kk
  15.  
  16.  
  17. def in_gamma(const_c, const_kk, const_h_t):
  18. return const_kk * const_h_t / const_c
  19.  
  20.  
  21. def in_gamma1(const_c, const_kk, const_h_t, const_h_r, const_r_i):
  22. return 1 + const_kk * const_h_t * (2 * const_r_i + const_h_r) / ((const_h_r ** 2) * const_r_i * const_c)
  23.  
  24.  
  25. def in_gamma2(const_kk, const_h_t, const_c, const_h_r):
  26. return const_kk * const_h_t / (const_c * (const_h_r ** 2))
  27.  
  28.  
  29. def in_gamma3(const_c, const_kk, const_h_t, const_h_r, const_r_i):
  30. return const_kk * const_h_t / (const_c * (const_h_r ** 2)) + in_gamma(const_c, const_kk, const_h_t) / (
  31. const_r_i * const_h_r)
  32.  
  33.  
  34. def method(h_t, h_r, t):
  35. r = np.arange(0, R + h_r, h_r)
  36. values = np.exp(-(r / (0.1 * R)) ** 2)
  37. coef = [[0] * 2] * (len(r) - 1)
  38. for time in np.arange(1, len(np.arange(0, t, h_t)), 1):
  39. for i in np.arange(0, len(r), 1):
  40. if i == 0:
  41. coef[i] = [1, 0]
  42. values[i] = np.exp(-(r[i] / (0.1 * R)) ** 2)
  43. elif i == len(r) - 1:
  44. values[i] = coef[i - 1][1] / (1 - coef[i - 1][0] + alpha * h_r / kk)
  45. else:
  46. if i == 1:
  47. A1 = (-1) * in_gamma3(c, kk, h_t, h_r, r[i])
  48. B1 = in_gamma1(c, kk, h_t, h_r, r[i]) - in_gamma2(kk, h_t, c, h_r)
  49. C1 = 0
  50. F1 = values[i]
  51. Alpha1 = - (A1 / (B1 + C1 * coef[i - 1][0]))
  52. Betta1 = ((F1 - C1 * coef[i - 1][1]) / (B1 + C1 * coef[i - 1][0]))
  53. coef[i] = [Alpha1, Betta1]
  54. elif i == len(r) - 2:
  55. AI = in_gamma1(c, kk, h_t, h_r, r[i]) * (1 + h_r * alpha / kk) - in_gamma3(c, kk, h_t, h_r, r[i])
  56. BI = 0
  57. CI = (-1) * in_gamma2(kk, h_t, c, h_r)
  58. FI = values[i]
  59. AlphaI = - (AI / (BI + CI * coef[i - 1][0]))
  60. BettaI = ((FI - CI * coef[i - 1][1]) / (BI + CI * coef[i - 1][0]))
  61. coef[i] = [AlphaI, BettaI]
  62. else:
  63. A = (-1) * in_gamma3(c, kk, h_t, h_r, r[i])
  64. B = in_gamma1(c, kk, h_t, h_r, r[i])
  65. C = (-1) * in_gamma2(kk, h_t, c, h_r)
  66. F = values[i]
  67. Alpha = - (A / (B + C * coef[i - 1][0]))
  68. Betta = ((F - C * coef[i - 1][1]) / (B + C * coef[i - 1][0]))
  69. coef[i] = [Alpha, Betta]
  70.  
  71. for i in np.arange(len(r) - 2, -1, -1):
  72. values[i] = coef[i][0] * values[i + 1] + coef[i][1]
  73. return [r, values]
  74.  
  75.  
  76. def f(x0, gamma):
  77. I = (math.tan(x0) - gamma / x0)
  78. return I
  79.  
  80.  
  81. def f1(x0, gamma):
  82. I = 1 / (math.cos(x0) * math.cos(x0)) + gamma / (x0 * x0)
  83. return I
  84.  
  85.  
  86. def newtons_method(x0, e, gamma):
  87. x0 = float(x0)
  88. while True:
  89. x1 = x0 - (f(x0, gamma) / f1(x0, gamma))
  90. if abs(x1 - x0) < e:
  91. return x1
  92. x0 = x1
  93.  
  94.  
  95. ""
  96.  
  97. # def sum():
  98. # Psi = []
  99. # resultsum = []
  100. # for i in range(1, 5 * n):
  101. # x.append4(newtons_method(i, e, gamma))
  102. # nu = sorted(list(set(x)))
  103. #
  104. # rm = np.arange(0, R, R / n)
  105. #
  106. # for i in range(1, n):
  107. # y = np.exp((-1) * (rm[i] / (0.1 * R)) ** 2) * math.cos(nu[i] * rm[i] / R)
  108. # coef = 4. * nu[i] / (2. * nu[i] * R + R * math.sin(2. * nu([i]))
  109. # Int = np.trapz(rm, y)
  110. #
  111. # Psi.append(Int * coef)
  112. # sumprom = 0
  113. #
  114. # for r in np.arange(0, R, R / n):
  115. # for i in range(1, n):
  116. # sumprom+=Psi(i) * np.exp((kk / (c) * (nu(i) ** 2) / R) * t * (-1)) * math.cos(nu[i] * r / R)
  117. # resultsum.append(sumprom)
  118. # sumprom = 0
  119. # return [rm, resultsum]
  120.  
  121.  
  122. [x, y] = method(0.2, 0.2, 10)
  123. # [a, b] = sum()
  124. plt.plot(x, y, color='green')
  125. plt.grid(True)
  126. plt.show(True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement