# Dynamical Systems

Dynamical systems are a very important part of Theoretical Mechanics. In our mechanics class, we use Lagrange's equations to find the equations of motion of a diversity of systems. Nevertheless, most of these equations are very hard or impossible to solve analytically. In this section, we are going to learn how to use the Runge-Kutta method to aproimate numerically the behaviour of a variety of dynamical systems.

## Hamilton's equations

As we know, one can perform a Legendre transformation to the Lagrangian of a system in order to obtain the Hamiltonian. With it, we can obtain a new set of first order differential equations that describes the evolution of the system:&#x20;

$$
\dot{q\_i} = \frac{\partial H}{\partial p\_i},\~\~\dot{p\_i} = - \frac{\partial H}{\partial q\_i}
$$

This is a system of equations that, with given initial conditions, can be solved using the Runge-Kutta method. To do this, we define a discrete time domain. Instead of having a set of continuos values in an interval, we define the following set of points:&#x20;

$$
{t\_i| t\_i = t\_0+i\Delta t\~\text{for}\~ i =1,2,...,Nt},\~\~\Delta t = \frac{tf}{Nt}
$$

The Runge-Kutta method states that, given the following initial value problem:

$$
\frac{d\vec{x}(t)}{dt} = \vec{F}(\vec{x}),\~\~\vec{x}(0) = \vec{x}\_0
$$

then, the function can be approximated by the following formula:

$$
\begin{eqnarray}
\vec{x}*i=\vec{x}(t\_i) &=& \vec{x}(t*{i-1}) + \frac{\vec{k\_1} + 2\vec{k\_2} + 2\vec{k\_3} + \vec{k\_4}}{6}\\
\vec{k\_1} &=& \vec{F}(\vec{x}(t\_{i-1})) \Delta t \\
\vec{k\_2} &=& \vec{F}(\vec{x}(t\_{i-1})+\frac{1}{2}\vec{k\_1}) \Delta t \\
\vec{k\_3} &=& \vec{F}(\vec{x}(t\_{i-1})+\frac{1}{2}\vec{k\_2}) \Delta t \\
\vec{k\_4} &=& \vec{F}(\vec{x}(t\_{i-1})+\vec{k\_3}) \Delta t \\
\end{eqnarray}
$$

We are going to use this method to solve a lot of sets of differential equations in the following sections.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://servicio-social.gitbook.io/computational-physics/dynamical-systems.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
