1

I have written a very basic simulation of a pendulum. I used the equation α = -g/l * sin(φ). I set g/l to 50, so I expect to get a period of 0.89 seconds (Using the formula 2π*√(l/g)). However, I get a period of around 6.5 seconds. The relevant code part is

let ang_acc = - 50.0 * pendulum.angle.to_radians().sin();
pendulum.ang_vel += ang_acc * dt;
pendulum.angle += pendulum.ang_vel * dt;

The complete code is on GitHub. I tried to make it as basic as possible and commented everything important.

ismxy
  • 21
  • 3
  • 3
    Your acceleration and velocity are in radians, but your angle is in degrees. You're missing a call to `to_degrees` somewhere. – Jmb Aug 04 '22 at 19:01
  • 1
    Which is why "I set g/l to 50" sounded like a red flag - when doing any simulation work, you have to always keep units in mind. With angles, even more so. – Dominik Stańczak Aug 04 '22 at 19:32
  • 1
    The general recommendation is to keep everything in radians, and only convert from/to degrees directly from user input or directly before output to the user. – PitaJ Aug 04 '22 at 19:34

0 Answers0