5. Simulating a Swinging Pendulum
Let the initial angle \(\theta_0 = \theta_{old}\) and initial velocity \(= v_{old}\). When the bob is released, \(\theta_{old}\) will reduce to \(\theta_{new}\) and \(v_{old}\) will change to \(v_{new}\), and so on.
The component \(mg \times sin(\theta)\) causes oscillation.
The equation of motion here is independent of mass, \(m\).
\(sin(\theta)\) is non-linear and is normally solved using a special case of the Taylor series, the Maclaurin series expansion (Knight & Adams, 1975) (Lam & Leary, 1979).
For small \(\theta\), \(\approx \frac{\pi}{12} \text{ radians}\), \(sin(\theta)\) can then be approximated to \(sin(\theta) \approx \theta\), resulting to \(\approx 1\% \text{ error}\).
However, considering a very small \(\theta\), we can approximate \(sin(\theta)\).
The following code simulates the motion of a swinging pendulum using numerical integration, based on the principles of Newtonian mechanics. The code defines the initial parameters of the pendulum, including its mass, length, initial angle, and velocity. The loop iterates over a range of time steps, calculating the position and velocity of the pendulum at each step. The plot displays the pendulum’s motion using matplotlib, with a red circle representing the bob and a gray line indicating the rod. The simulation could be improved by using higher-order integration schemes, adding nonlinear damping terms, simulating multiple pendulums, and allowing user input. The code is useful for mechatronics engineers, who can use it to design and optimize control systems, simulate the motion of robotic arms, test and calibrate sensors, and harvest energy from mechanical systems. Check this code on GitHub and you are welcome to improve it.
Here is a swinging single pendulum simulation. Import the required libraries.
|
Initialize variables.
|
Solve equations involved and store the data in an array.
|
Prepare an empty plot.
|
Make a fuction to update the plot.
|
Animate your plot.
|
Add Comment
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
- Your name, rating, website address, town, country, state and comment will be publicly displayed if entered.
- Aside from the data entered into these form fields, other stored data about your comment will include:
- Your IP address (not displayed)
- The time/date of your submission (displayed)
- Your email address will not be shared. It is collected for only two reasons:
- Administrative purposes, should a need to contact you arise.
- To inform you of new comments, should you subscribe to receive notifications.
- A cookie may be set on your computer. This is used to remember your inputs. It will expire by itself.
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
- Although the administrator will attempt to moderate comments, it is impossible for every comment to have been moderated at any given time.
- You acknowledge that all comments express the views and opinions of the original author and not those of the administrator.
- You agree not to post any material which is knowingly false, obscene, hateful, threatening, harassing or invasive of a person's privacy.
- The administrator has the right to edit, move or remove any comment for any reason and without notice.
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
Comments