<jupyter_start><jupyter_text>Taylor problem 4.37 templateIn this problem the potential energy $U(\phi)$ depends on the masses $m$ and $M$, with the qualitative behavior of the system starting at $\phi=0$ depending on the ratio $m/M$. We will determine the critical value of this ratio from the graphs of the potential energy (corresponding to taking $\phi = 0$, meaning $M$ at its lowest, as the zero of potential energy):$\begin{align}  U(\phi) = M g R (1-\cos\phi) - m g R \phi  \;.\end{align}$**This notebook has a different potential energy function that has the same qualitative behavior.  Your job is to implement the correct formula.  Places you need to change are marked with .**<jupyter_code>%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Make a plot of the potential with simple values of the constants.<jupyter_code>def U(phi, M_big, m_small, R=1., g=1.):
    """Potential energy for the system in Taylor, problem 4.37."""
    return M_big*g*R*(1.-np.exp(-phi**4/2.)) - m_small*g*R*phi  ### made up U(\phi)
# set non-essential constants to 1 (doesn't change shapes)
R = 1.
g = 1.
M_big = 1.

phi_pts = np.arange(0., 3.5, 0.01)

fig_U = plt.figure()
ax_U = fig_U.add_subplot(1,1,1)

m_small = 0.5  ### different values
U_of_phi_pts = U(phi_pts, M_big, m_small)
ax_U.plot(phi_pts, U_of_phi_pts, 'b-', label=fr'$m/M = {m_small:0.1f}$', lw=2)

m_small = 0.7  ### different values
U_of_phi_pts = U(phi_pts, M_big, m_small)
ax_U.plot(phi_pts, U_of_phi_pts, 'g-', label=fr'$m/M = {m_small:0.1f}$', lw=2)


ax_U.set_xlabel(r'$\phi$')
ax_U.set_ylabel(r'$U(\phi)$')

ax_U.set_xlim(0, 3.5)
#ax_U.set_ylim(-1., 6.)

# draw a black horizontal line at 0 but with alpha=0.3 so less distracting
ax_U.axhline(0., color='black', alpha=0.3 )  
ax_U.legend();<jupyter_output><empty_output><jupyter_text>Let's plot it with a slider to find the critical value (where the curve is tangent to the line at zero.  Ok, let's change $m/M$ with a slider:<jupyter_code>from ipywidgets import interact, fixed
import ipywidgets as widgets
# set non-essential constants to 1 (doesn't change shapes)
R = 1.
g = 1.
M_big = 1.

def plot_U_given_m_over_M(m_over_M, M_big=1., R=1., g=1.):
    ""
    phi_pts = np.arange(0., 3.5, 0.01)

    fig_U = plt.figure()
    ax_U = fig_U.add_subplot(1,1,1)

    m_small = m_over_M * M_big
    U_of_phi_pts = U(phi_pts, M_big, m_small)
    ax_U.plot(phi_pts, U_of_phi_pts, 'r-', 
              label=rf'$m/M = {m_over_M:.2f}$', lw=2)

    ax_U.set_xlabel(r'$\phi$')
    ax_U.set_ylabel(r'$U(\phi)$')

    ax_U.set_xlim(0, 3.5)
    #ax_U.set_ylim(-1., 6.)

    # draw a black horizontal line at 0 but with alpha=0.3 so less distracting
    ax_U.axhline(0., color='black', alpha=0.3 )  

    ax_U.legend();

# fix the values of M_big, R, and g
interact(plot_U_given_m_over_M, 
         m_over_M = widgets.FloatSlider(min=0., max=1., step=0.01, 
                                        continuous_update=False,
                                        value=0.5, readout_format='.3f'), 
         M_big=fixed(1.), R=fixed(1.), g=fixed(1.));<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14381164492523066, 'fraction_numerical': 0.027998727330575884, 'mean_word_length': 3.5499276410998553, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '481479', 'license': 'MIT', 'n_tokens_mistral': 1285, 'n_tokens_neox': 1223, 'n_words': 334, 'path': '2020_week_1/Taylor_problem_4.37_template.ipynb', 'repo_name': 'CLima86/Physics_5300_CDL', 'size': '3143'}