deepskies / DeepBench

Simulation library for very simple simulations to benchmark machine learning algorithms
Apache License 2.0
3 stars 0 forks source link

Pendulum x position is wrong, bug with the placement of t #121

Closed beckynevin closed 11 months ago

beckynevin commented 1 year ago

Describe the bug The pendulum x position always begins at x = 0 for t = 0. It should begin at a different x value (positive or negative) if the starting angle of the pendulum is not 0 degrees. This makes me think there's some bug having to do with parenthesis in the code. I would like to double check the math of the pendulum as we debug this.

To Reproduce Steps to reproduce the behavior:

  1. Go to the example notebook for the pendulum
  2. Alter the starting angle
  3. Re-create the plot at the bottom
  4. Observe that the starting position (at t = 0) is always x = 0 regardless of the starting angle.

Expected behavior A clear and concise description of what you expected to happen.

Screenshots

image
beckynevin commented 1 year ago

image ^Here's the image of the output plot from the example notebook.

bnord commented 1 year ago

Should there be a phase variable in the sine or cosine that represents or connects to the starting position/angle?

beckynevin commented 1 year ago

Currently we have:

theta_time = starting_angle_values * np.cos(np.sqrt(acceleration_values / pendulum_arm_length_values))
pos_x =  pendulum_arm_length_values * np.sin(theta_time * time)

I think it should be:

theta_time = starting_angle_values * np.cos(np.sqrt(acceleration_values / pendulum_arm_length_values) * time)
pos_x =  pendulum_arm_length_values * np.sin(theta_time)

Where the time is within the cosine argument.

beckynevin commented 1 year ago

I think the phase variable of which. you speak is the sqrt(a/L) part?

bnord commented 1 year ago

Hmm. I'm not able to verify or falsify on the fly right now.

Does the starting position/angle get a variable anywhere else? I think it would be emerge as a constant of integration somewhere.

Should we write down the proof to check?

beckynevin commented 1 year ago

Okay, I was able to verify this is the correct formula for the simple pendulum under the small angle approximation using this website - https://www.acs.psu.edu/drussell/Demos/Pendulum/Pendulum.html. But this brings up another issue for me. We are currently swinging the pendulum in big angles, violating the small angle approximation theta \approx sin theta. Do we need to adjust our approach?

voetberg commented 11 months ago

@beckynevin was this solved in release 2.2.0?

beckynevin commented 11 months ago

This was solved, I'm closing the issue.