Skip to content

Instantly share code, notes, and snippets.

@pozitron57
Last active May 24, 2024 19:22
Show Gist options
  • Save pozitron57/5b9a640485d3b349c0bb4c8a3af6c320 to your computer and use it in GitHub Desktop.
Save pozitron57/5b9a640485d3b349c0bb4c8a3af6c320 to your computer and use it in GitHub Desktop.
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rc, rcParams
from matplotlib.ticker import FuncFormatter
from matplotlib.ticker import MultipleLocator
# Plot setup {{{
lw = 2
rcParams['font.size'] = 23
#rcParams['text.usetex'] = True
#rcParams['font.sans-serif'] = ['Computer Modern']
#rc('text.latex', preamble=r'\usepackage[T2A]{fontenc} \usepackage[utf8]{inputenc} \usepackage{amsmath} \usepackage{bm}')
plt.rcParams.update({
"text.usetex": False,
"mathtext.fontset": "custom",
"mathtext.it": "STIX Two Text:italic",
"mathtext.rm": "STIX Two Text",
"mathtext.sf": "STIX Two Text",
"font.sans-serif": "STIX Two Text",
})
rc('axes', linewidth=lw)
rc('xtick.major', size=4, width=lw)
rc('ytick.major', size=4, width=lw)
fig, ax = plt.subplots(figsize=(12,7))
fig.subplots_adjust(left=.20, bottom=.13, right=.90, top=.68)
# Set comma as a decimal separator (bad)
import locale
locale.setlocale(locale.LC_NUMERIC, 'ru_RU')
rcParams['axes.formatter.use_locale'] = True
def format_decimal(value, tick_number):
value = round(value, 2) # Fixes 0,60000000000001 instead of 0,6
return '$' + str(value).replace('.', '{,}') + '$'
ax.xaxis.set_major_formatter(FuncFormatter(format_decimal))
# def custom_formatter(x, pos):
# return "{:.2f}".format(x).replace('.', ',')
# ax.yaxis.set_major_formatter(FuncFormatter(custom_formatter))
#}}}
m = 0.1
g = 10
L = 1.5/2
l = 1.2/2
x = np.linspace(1e-20, L*0.99999, 100000)
sin_alpha = (L-x) / L
cos_alpha = np.sqrt(L**2 - (L-x)**2) / L
tg_alpha = sin_alpha / cos_alpha
v = np.sqrt(2*g) * (2*L*x-x**2)**(3/4) / (L**2+2*L*x-x**2)**(1/2)
v3 = v * tg_alpha
a = np.sqrt(2*g) * v * (L-x)*(-x**2/2 + L*x + 3*L**2/2) / ((L**2 + 2*L*x - x**2)**(3/2) * (x*(2*L-x))**(1/4))
a3_der = np.sqrt(2*g) * v * (L**4/2 - 4*L**3*x + 2*L*x**3 - x**4/2) / ((L**2 + 2*L*x - x**2)** (3/2) * (2*L*x-x**2)**(3/4) )
T = m*a / sin_alpha
a3_dyn = (m*g - 2*T*cos_alpha) / m
lw = 2.3
## PLOT a(x)
ax.plot(x,a, label='$a$ (крайние бусинки)', lw=lw)
ax.plot(x,a3_der, label='$a_3$ (нижняя бусинка)', lw=lw, color='C3')
ax.plot(x,a*tg_alpha, label='$a_3$ (авторское)', lw=lw*0.8, ls=(0,(4,2.8)), color='C2')
ax.set_ylabel(r'$a, \text{м}/\text{с}^2$', labelpad=13)
### PLOT v(x)
#ax.plot(x,v, label='$ʋ$ (крайние бусинки)', lw=lw, color='C0')
#ax.plot(x,v3, label='$ʋ_3$ (нижняя бусинка)', lw=lw, color='C3')
#ax.set_ylabel(r'$ʋ, \text{м}/\text{с}$', labelpad=13)
### PLOT T(x)
#ax.plot(x,T, label='$T$', lw=lw, color='C0')
#ax.set_ylabel(r'$T,$ Н', labelpad=13)
#ax.yaxis.set_major_formatter(FuncFormatter(format_decimal))
plt.figtext(0.23, 0.73, r'$m = {}$ кг'.format(m).replace('.', '{,}') )
ax.set_xlabel(r'$x,$м')
#ax.plot(x,T, label='$T$', lw=lw)
#ax.plot(x,Ts, label='$T\'$', lw=lw)
#ax.plot([0,L], [m*g, m*g], label='$mg$', lw=lw)
ax.set_xticks([0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.75])
ax.legend()
ax.grid()
plt.show()
#a3 = - sqrt(g) * sqrt(-x**2+2*L*x+L**2) * (x**4-4*l*x**3+8*l**3*x-l**4) * xdot / (2*L*x-x**2)**(3/4) * sqrt(2) * (x**4 - 4*L*x**3 + 2*L**2*x**2 + 4*L**3*x + L**4)
#a3 = sqrt(2*g) * xdot * (L**4/2 - 4*L**3*x + 2*L*x**3 - x**4/2) / (L**2 + 2*L*x - x**2)**(3/2) * (2*L*x-x**2)**(3/4)
#a = np.sqrt(g) * np.sqrt(-x**2 + 2*L*x + L**2) * (np.sqrt(2)*x**3 - 3*np.sqrt(2)*L*x**2 - np.sqrt(2)*L**2*x + 3*np.sqrt(2)*L**3) * xdot / ((2*l*x - x**2)**(1/4) * (2*x**4 - 8*l*x**3 + 4*l**2*x**2 + 8*l**3*x + 2*l**4))
#a = sqrt(2*g) * xdot * (L-x) * (-x**2/2+L*x+3*L**2/2) / ((L**2 + 2*L*x - x**2)**(3/2) * (2*L*x-x**2)**(1/4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment