function dydt = pendulum_driven(t, y) beta = 0.2; omega0 = 1.0; Fd = 1.2; omegad = 2/3; theta = y(1); omega = y(2); phi = y(3); dtheta = omega; domega = -beta*omega - omega0^2*sin(theta) + Fd*cos(phi); dphi = omegad; dydt = [dtheta; domega; dphi]; end % Solve [t, y] = ode45(@pendulum_driven, [0 200], [0.1 0 0]); theta = y(:,1);
import numpy as np import matplotlib.pyplot as plt omega0 = 1.0 dt = 0.01 t_max = 20.0 n_steps = int(t_max / dt) function dydt = pendulum_driven(t, y) beta = 0
Given ( (\theta_n, \omega_n) ), compute: [ k_1^\theta = \omega_n, \quad k_1^\omega = -\fracgL\sin\theta_n, ] [ k_2^\theta = \omega_n + \frac\Delta t2k_1^\omega, \quad k_2^\omega = -\fracgL\sin(\theta_n + \frac\Delta t2k_1^\theta), ] etc. Then update: [ \theta_n+1 = \theta_n + \frac\Delta t6(k_1^\theta + 2k_2^\theta + 2k_3^\theta + k_4^\theta), ] [ \omega_n+1 = \omega_n + \frac\Delta t6(k_1^\omega + 2k_2^\omega + 2k_3^\omega + k_4^\omega). ] function dydt = pendulum_driven(t