Skip to content

Instantly share code, notes, and snippets.

@pozitron57
Created November 15, 2023 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pozitron57/4897a484741a528ed0fad843e2caebc3 to your computer and use it in GitHub Desktop.
Save pozitron57/4897a484741a528ed0fad843e2caebc3 to your computer and use it in GitHub Desktop.
Animation F_friction(t) plot for phys.pro/problems/237/
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rc, rcParams
from matplotlib.ticker import FuncFormatter
from matplotlib.ticker import MultipleLocator
# Set parameters
m = 2 # kg
R = 1 # m
g = 10 # m/s²
a = np.radians(30) # deg
T = 5 # s
w = 2*np.pi / T # rad/s
t = np.linspace(0, 2*T, 1000)
R_values = np.linspace(0, 3.1*g*np.sin(a)/w**2, 400)
for R in R_values:
# Plot setup {{{
lw = 2
k=1.4
rcParams['font.size'] = 24
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}')
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.yaxis.set_major_formatter(FuncFormatter(format_decimal))
#ax.xaxis.set_major_formatter(FuncFormatter(format_decimal))
#}}}
F = m * g * np.sqrt((w**2 * R/g)**2 + 2 * w**2 * R * np.sin(a)/g * np.cos(w*t) + np.sin(a)**2)
ax.plot(t, F, label=r'$F_\textrm{тр}(t) = mg \sqrt{\left(\dfrac{\omega^2R}{g}\right)^{\kern-9pt 2} + \dfrac{2\omega^2R\sin\alpha}{g} \cdot \cos\omega t + \sin^2\alpha}$', lw=lw*1.5)
print( round(R,3) )
plt.figtext(0.27, 0.73, r'$m\omega^2R = {}\cdot mg\sin\alpha$'.format('{:0.2f}'.format(round( w**2*R/(g*np.sin(a)), 2)) ).replace('.', '{,}') )
plt.figtext(0.67, 0.73, r'$mg\sin\alpha = {}\;\textrm{{Н}}$'.format(round(m*g*np.sin(a)) ) )
ax.set_xlabel(r'$t, \textrm{с}$')
ax.set_ylabel(r'$F_\textrm{тр},\;\textrm{Н}$', labelpad=13)
ax.grid()
ax.legend(loc='upper center', bbox_to_anchor=(0.5, 1.6), ncol=1, fancybox=False, shadow=False)
ax.set_ylim([0,42])
plt.savefig('/Users/slisakov/Yandex.disk.localized/documents/scripts/1514_school/237/' + str('{:0.3f}'.format(round(R,3)))+'.pdf', bbox_inches='tight')
plt.close()
# Then do
# convert -loop 0 *pdf 237.gif
# using imagemagick
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment