Advertisement
mirosh111000

Завдання

May 29th, 2023 (edited)
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.87 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import pandas as pd
  4.  
  5. def f(x):
  6.     return alpha * (1 - x) - x * np.exp(-2*epsilon*x)
  7.  
  8. def V(x):
  9.     return -alpha*(x - (1/2)*x**2) + (1/4)*(-2 * x * epsilon * np.exp(-2*epsilon*x) - np.exp(-2*epsilon*x)) / (epsilon**2)
  10.  
  11. def alpha_st(x):
  12.     return (x * np.exp(-2*epsilon*x)) / (1 - x)
  13.  
  14. def sts():
  15.     x = dx
  16.     while x <= (1 - dx):
  17.         if ( (x - dx < 0) and (f(x) > 0) ) or ( (f(x - dx) > 0) and (f(x) < 0) ):
  18.            y.append(x)
  19.     x += dx
  20.  
  21. def grafik(x, y):
  22.  
  23.     plt.title(f"alpha(x)")
  24.     plt.xlabel("alpha")
  25.     plt.ylabel("x")
  26.     plt.grid()
  27.     for i in range(len(x)):
  28.         plt.plot(x[i], y[i], 'o',  label=f'epsilon = {i+1}')
  29.     plt.legend()
  30.     plt.show()
  31.  
  32.  
  33.  
  34. X1 = []
  35. Y1 = []
  36. dx = 0.0001
  37. alpha = 0
  38. for i in range(1, 7):
  39.     epsilon = i
  40.     y = []
  41.     dx = 0.0001
  42.     alpha = 0
  43.     X = []
  44.     Y = []
  45.     while alpha < 0.15:
  46.         x = 0
  47.         while x <= (1 - dx):
  48.             if (((f(x - dx) < 0) and (f(x) > 0)) or ((f(x - dx) > 0) and (f(x) < 0))):
  49.                     X.append(alpha)
  50.                     Y.append(x)
  51.  
  52.  
  53.             x += dx
  54.         alpha += 0.001
  55.     X1.append(X)
  56.     Y1.append(Y)
  57.  
  58. grafik(X1, Y1)
  59.  
  60. x_max = []
  61. y_max = []
  62. x_min = []
  63. y_min = []
  64. eps = np.arange(1, 6, 0.1)
  65. for epsilon in eps:
  66.     x = 2 * dx
  67.     while x < (1.0 - dx):
  68.  
  69.         a1 = alpha_st(x - dx)
  70.         a2 = alpha_st(x)
  71.         a3 = alpha_st(x + dx)
  72.  
  73.         if (a1 < a2) and (a3 < a2):
  74.             x_max.append(a2)
  75.             y_max.append(epsilon)
  76.  
  77.         if (a1 > a2) and (a3 > a2):
  78.             x_min.append(a2)
  79.             y_min.append(epsilon)
  80.  
  81.         x += dx
  82.  
  83. plt.title(f"Фазова діаграма")
  84. plt.xlabel("alpha")
  85. plt.ylabel("eps")
  86. plt.grid()
  87. plt.plot(x_max, y_max, label='maximum')
  88. plt.plot(x_min, y_min, label='minimum')
  89. plt.legend()
  90. plt.show()
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement