Simulation of a pendulum without using the angle with the Euler-Cromer method.

59 Views Asked by At

I am trying to create a computer simulation of a simple pendulum with a mass $m$ hanging from an inextensible and negligibly massless string, but without using the angle, only using the positions of the constraint $r_2$ on which the mass is hung and of the mass itself $r_1$.

Assuming that the implementation of the simulation in any programming language (in my case javascript) is correct, for the simulation I had thought of using the Euler-Cromer method, already used with the angle obtaining a fairly realistic approximation. While in this case, using the positions of the two elements, I obtain an anomalous behavior. What I start from to find the function $f$ of the method is the image below.

Pendulum simulation

The force acting on the motion is the tangential component of the gravitational force $\overrightarrow{P_t}$, since the radial component $\overrightarrow{P_r}$ is canceled out by the tension of the string. At this point, to calculate the tangential component, you have to do $\overrightarrow{P_t}=\overrightarrow{P}-\overrightarrow{P_r}$. So

$$ \overrightarrow{P_r}=\frac{\overrightarrow{P}\cdot \overrightarrow{r_{21}}}{|\overrightarrow{r_{21}}|^2}\cdot \overrightarrow{r_{21}} $$

This is the calculation of the projection of $\overrightarrow{P}$ onto $\overrightarrow{r_{21}}$. Since the string is inextensible, we can say that $|\overrightarrow{r_{21}}|=\mathit{l}$, where $\mathit{l}$ is the length of the string. $$ \overrightarrow{P_r}=\frac{\overrightarrow{P}\cdot \overrightarrow{r_{21}}}{\mathit{l}^2}\cdot \overrightarrow{r_{21}} $$

At each step of the algorithm, I always recalculate $\overrightarrow{r_{21}}$ which is $\overrightarrow{r_1}-\overrightarrow{r_2}$. So in the end: $$ \mathit{f}\left(t,\overrightarrow{r_1}(t)\right)=\overrightarrow{P}-\frac{\overrightarrow{P}\cdot \overrightarrow{r_{21}}}{\mathit{l}^2}\cdot \overrightarrow{r_{21}} $$

Since $\overrightarrow{P_t}$ is the force, we can say that $\overrightarrow{P_t}=\mathit{f}\left(t,\overrightarrow{r_1}(t)\right)=m\frac{d\overrightarrow{v}(t)}{dt}$ and therefore the steps of the final method are as follows.

$$ \overrightarrow{v_{n+1}}=\overrightarrow{v_n}+\frac{\overrightarrow{P}-\frac{\overrightarrow{P} \cdot \overrightarrow{r_{21_n}}}{\mathit{l}^2}\cdot \overrightarrow{r_{21_n}}}{m}\cdot \Delta t $$ Where $$ \overrightarrow{r_{21_n}}=\overrightarrow{r_{1_n}}-\overrightarrow{r_2} $$ Then $$ \overrightarrow{r_{1_{n+1}}}=\overrightarrow{r_{1_n}}+\overrightarrow{v_{n+1}}\cdot \Delta t $$ $$ \overrightarrow{r_{21_{n+1}}}=\overrightarrow{r_{1_{n+1}}}-\overrightarrow{r_2} $$

Note: $r_2$ is fixed, therefore it is constant. I wanted to know if the mathematical calculations and reasoning are correct, because as shown in the next image (three points of the simulation), the animation is completely unrealistic and inaccurate.

enter image description here

Where the dashed circle is the trajectory it should follow. As you can see, the simulation is very unrealistic. Mine was just a test to understand if it was possible to simulate this pendulum using the Euler-Cromer method without using the angle. It could be that the method's precision is not accurate enough for the trajectory to be realistic, making it unstable, and perhaps with more advanced methods like Runge-Kutta, the approximation would be better. I also tried the Verlet method, but it doesn't change much. I haven't tried Runge-Kutta yet, but before doing so, I would like to be sure that the problem lies in the precision of the calculations rather than the calculated expressions.

1

There are 1 best solutions below

7
On

I understood the problem. As @m-stgt says, the 'approximate' velocity is not tangent to the circle (I think he wrote it wrong). This generates an error both in the velocity and consequently in the position. To visualize it, I added the velocity vector to the simulation, where it is possible to see that the velocity (in purple) is not parallel to the tangential force (in blue), and the latter is tangent to the dashed circle by construction. Below the image.

velocity visualization

So could I "rotate" the velocity (without changing the magnitude) so that it is always tangent to the circle, thus reducing the error, or changing to a more precise method where the velocity is always tangent can solve the problem?