{"id":18637608,"url":"https://github.com/justin-marian/double-pendulum","last_synced_at":"2025-11-04T14:30:30.371Z","repository":{"id":226145174,"uuid":"767186494","full_name":"justin-marian/double-pendulum","owner":"justin-marian","description":"Motion of 3 gravitational double pendulums and plots there trajectories.","archived":false,"fork":false,"pushed_at":"2024-03-08T21:30:14.000Z","size":9526,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-27T09:12:30.543Z","etag":null,"topics":["double-pendulum-simulation","matlab","physics-simulation","plotting","simulation-modeling"],"latest_commit_sha":null,"homepage":"","language":"MATLAB","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/justin-marian.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-04T21:15:50.000Z","updated_at":"2024-03-06T04:36:50.000Z","dependencies_parsed_at":"2024-03-08T21:50:42.519Z","dependency_job_id":null,"html_url":"https://github.com/justin-marian/double-pendulum","commit_stats":null,"previous_names":["justin-marian/double-pendulum"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justin-marian%2Fdouble-pendulum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justin-marian%2Fdouble-pendulum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justin-marian%2Fdouble-pendulum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justin-marian%2Fdouble-pendulum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/justin-marian","download_url":"https://codeload.github.com/justin-marian/double-pendulum/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239433910,"owners_count":19637806,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["double-pendulum-simulation","matlab","physics-simulation","plotting","simulation-modeling"],"created_at":"2024-11-07T05:37:05.553Z","updated_at":"2025-11-04T14:30:30.340Z","avatar_url":"https://github.com/justin-marian.png","language":"MATLAB","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Double Pendulum\n\n## Description\n\nThe Double Pendulum is a `MATLAB` code that simulates the **motion of three double pendulum systems** with different physical parameters. It calculates the motion of each pendulum using recurrence relations and then visualizes the motion using graphical simulation.\n\nThe dynamics of the double pendulum are described using **Lagrangian mechanics** and **Runge-Kutta (RK4)**, which provides a more elegant and efficient way to derive the equations of motion for complex systems.\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/justin-marian/double-pendulum/tree/main/demo/simulation.mp4\" style=\"width: 75%; height: 100%;\" \u003e\n        \u003cimg src=\"/images/three_double_pendulums.png\" alt=\"VELOCITY_POSITION_CURVE\" style=\"width: 37%; height: auto;\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/justin-marian/double-pendulum/tree/main/demo/simulation.mp4\" style=\"width: 75%; height: 100%;\" \u003e\n        \u003cimg src=\"/images/runge_kutta_4ode.png\" alt=\"RUNGE_KUTTA_4ODE\" style=\"width: 45%; height: auto;\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n## Physical Parameters\n\n- **Pendulum Parameters:** Each pendulum system is defined by its lengths (`L1` and `L2`) and masses (`m1` and `m2`). These parameters determine the geometry and inertia of the pendulum systems, influencing their motion.\n- **Initial Conditions:** Initial angles (`theta1` and `theta2`) and initial angular velocities (`OM1` and `OM2`)  specify the starting configuration and motion of each pendulum system. These conditions play a crucial role in determining the subsequent motion and behavior of the systems.\n\n## Simulation Settings\n\n- **Time Settings:** The simulation duration is determined by the characteristic time of the double pendulum motion. The simulation time is discretized into a specified number of time steps.\n- **Recurrence Cycle:** Recurrence relations are used to calculate the motion of each pendulum system.\n- **Energy Calculation:** The kinetic and potential energies of each pendulum system are calculated at each time simulation step (`1cs`).\n- **Graphical Simulation:** The motion of the pendulums is visualized using a graphical simulation.\n- **Tracebacks:** The pendulum positions and bottom objects' positions are also plotted during the simulation.\n\n## Lagrangian Equations\n\nThe **Lagrangian** ($\\mathcal{L}$) of the double pendulum is given by the difference between the **kinetic energy** (**$T$**) and the **potential energy** (**$U$**) of the system:\n\n**Kinetic Energy (T):**\n\n$$T = \\frac{1}{2} m_1 L_1^2 \\dot{\\theta}_1^2 + \\frac{1}{2} m_2 (L_1^2 \\dot{\\theta}_1^2 + L_2^2 \\dot{\\theta}_2^2 + 2 L_1 L_2 \\dot{\\theta}_1 \\dot{\\theta}_2 \\cos(\\theta_1 - \\theta_2))$$\n\n**Potential Energy (U):**\n\n$$U = -m_1 g L_1 \\cos(\\theta_1) - m_2 g L_1 \\cos(\\theta_1) + L_2 \\cos(\\theta_2)$$\n\nThe total energy of the double pendulum system, given by the ***sum of kinetic energy (T) and potential energy (U), must remain constant over time***. In theory, the total energy should be conserved throughout the simulation due to the **ideal** nature of the system, which assumes the *absence of friction or aerodynamic resistance*.\n\n### Equations of Motion\n\nThe equations of motion for the double pendulum are derived by applying the **Euler-Lagrange** equations to the Lagrangian. These equations are ***second-order ordinary differential equations (ODE2)*** that describe the evolution of the angles $\\theta_1$ and $\\theta_2$ over time.\n\nThe **Euler-Lagrange** equations for the double pendulum are given by:\n\n$$ \\frac{d}{dt} \\left(\\frac{\\partial \\mathcal{L}}{\\partial \\dot{\\theta}_1}\\right) - \\frac{\\partial \\mathcal{L}}{\\partial \\theta_1} = 0 $$\n\n$$ \\frac{d}{dt} \\left(\\frac{\\partial \\mathcal{L}}{\\partial \\dot{\\theta}_2}\\right) - \\frac{\\partial \\mathcal{L}}{\\partial \\theta_2} = 0 $$\n\n## Runge-Kutta (ODE4)\n\nThe **Runge-Kutta** is used for solving ordinary differential equations. Specifically, the ***fourth-order variant, RK4***, is widely used. It estimates the solution at the next time step based on the solution and its derivative at the current time step. By iteratively applying this process, RK4 generates a numerical solution to the ODE.\n\n- **RK4 Process**: Estimates the solution at the next time step based on the current solution and its derivative. This iterative process generates a numerical solution to the ODE.\n- **Discretization of Time Domain**: RK4 discretizes the time domain into small intervals, enabling the computation of angular positions and velocities of the pendulum at each step.\n\n### Algorithm Runge-Kutta\n\nThis pseudocode outlines the implementation of the **Runge-Kutta (RK4)** method for numerically solving ordinary differential equations (**ODEs**):\n\n- **$k_1 \\gets h \\cdot f(t_n, y_n)$:** Computes the slope at **$(t_n, y_n)$**, scaled by the step size $h$.\n- **$k_2 \\gets h \\cdot f(t_n + \\frac{h}{2}, y_n + \\frac{k_1}{2})$:** Computes the slope at the midpoint, using **$k_1$** adjusted state.\n- **$k_3 \\gets h \\cdot f(t_n + \\frac{h}{2}, y_n + \\frac{k_2}{2})$:** Computes slope at midpoint, using **$k_2$** adjusted state.\n- **$k_4 \\gets h \\cdot f(t_n + h, y_n + k_3)$:** Computes slope at the next step, using **$k_3$** adjusted state.\n- **$y_{n+1} \\gets y_n + \\frac{1}{6}(k_1 + 2k_2 + 2k_3 + k_4)$:** Updates state using **weighted average** of slopes.\n- **$t_{n+1} \\gets t_n + h$:** Updates **time** to the next step.\n\n## Numerical aproximations\n\nDue to numerical approximations or errors in the simulation, there might be a small deviation in the total energy, typically within the range of **0.01 to 0.1**. Vigilantly monitoring this deviation can help ensure the accuracy and stability of the simulation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjustin-marian%2Fdouble-pendulum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjustin-marian%2Fdouble-pendulum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjustin-marian%2Fdouble-pendulum/lists"}