<jupyter_start><jupyter_text>Basic 2-dimensional ODE solution<jupyter_code># This is a standard initalisation code - no need to change this
# It loads basic fast array code, plot library and ODE solver
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp
%matplotlib inline
%config InlineBackend.figure_formats={'retina','png'}<jupyter_output><empty_output><jupyter_text>System definitionSolving parametric pendulum$$\ddot{x}+\gamma\dot{x}+\omega_0^2(1+h \cos(2t))x=0$$<jupyter_code>def f(t, X):
    x = X[0]
    y = X[1]
    return [ y,
             -gamma*y-w02*(1+h*np.cos(2*t))*np.sin(x) ]<jupyter_output><empty_output><jupyter_text>Simple solution Let us just solve the equations for some initial conditions and plot the solution.Note the message `'The solver successfully reached the end of the integration interval.'`. It is good to check that it is the case -- sometimes the solver fails to do this!<jupyter_code>def hcrit(w02, gamma):
    return 2*np.sqrt((1-w02)**2+gamma**2/w02**2)
gamma=0.02
w02=1.0268**2
h=0.1
print(hcrit(w02,gamma))
tspan = (0, 540) # time range for the solution
x0 = [0.2, 0.0]  # initial conditions

#t_eval = np.linspace(tspan[0], tspan[1], num=500) # Make reported solution "smooth"
## Solve, and return solution at t_eval moments
xs = solve_ivp(f, tspan, x0, rtol=1e-13, atol=1e-13)
#xs
fig = plt.figure(figsize=(12,6))
ax1, ax2 = fig.subplots(1,2)

ax1.plot(xs.t, xs.y[0,:], label="$x_1$")
#ax1.plot(xs.t, xs.y[1,:], label="$x_2$")
#ax1.plot(xs.t, x0[0]*np.cos(np.sqrt(w02)*xs.t))
ax1.set_xlabel("$t$")
ax1.grid()
ax1.legend()

ax2.plot(xs.y[0,:], xs.y[1,:])
ax2.set_xlabel("$x_1$")
ax2.set_ylabel("$x_2$")
ax2.grid()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16676350958744915, 'fraction_numerical': 0.05113306217315514, 'mean_word_length': 5.49811320754717, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '310224', 'license': 'MIT', 'n_tokens_mistral': 739, 'n_tokens_neox': 706, 'n_words': 164, 'path': 'simple_parametricpendulum.ipynb', 'repo_name': 'fedxa/PHYS30471', 'size': '1721'}