Oscillatory motion of a Pendulum

To simulate the oscillatory behavior of a pendulum having a second order ODE.
26 descargas
Actualizado 14 jun 2021

Ver licencia

Here are few points to sum up the visualization of code for a better perspective.
  1. Initially the constants are declared before moving onto the solver part in order to maintain the effectiveness of code.
  2. Moving on, we declared the time range required for the bob to plunge between, along with mentioning its iteration as well (which appears to be 500 in our case).
  3. Previously the used defined function is declared and implemented to see the relevant inference is being show cased or not. If not, tweak the UD function accordingly until we get the desired result.
  4. Then, after saving the UD function we get then go for the solver part wherein, we declare the get the solution for the ODE in terms of matrix (1X500, 500X1) respectively and plot them accordingly as “Ang Disp and Ang. Vel Vs Time” and “Ang. Disp Vs Ang. Vel” using markers, face-colors and legends respectively.
  5. Further, for the iterative-part, we create a for-loop to nest the “line of pendulum; where it’s kept, pendulum’s bob, it’s string and the motion” by the help of plots, linewidths and equations functions. We declare an initial condition of x0 and y0 i.e., where the bob situates itself first and then tweaking the conditions until we receive a clear pendulum’s motion.
  6. We set a frame counter in order to reduce the timesteps as the values should be integral and not decimal so for ease of access, counter value (ct) is set to 1 (initially)
  7. Depending on the time range we classified above, we fix our axis accordingly in between 0 and 2 and go further for movie animation in MATLAB for the animation of our pendulum’s motion
  8. After ending the for-loop, we increment the counter value to plus 1 for loop to run infinitely (motion of pendulum).
  9. We use a command called “getframe” ONLY IN MATLAB for storing and saving the 500 iterated images for pendulum’s motion. This command also helps in stitching all the 500 generated images and converts it into a gif, respectively.
  10. Finally, we make the use of movie maker function already embedded in MATLAB, for making a gif and saving it in the form of a “avi” file in our internal storage.

Citar como

Iyer Aditya Ramesh (2024). Oscillatory motion of a Pendulum (https://www.mathworks.com/matlabcentral/fileexchange/94090-oscillatory-motion-of-a-pendulum), MATLAB Central File Exchange. Recuperado .

Compatibilidad con la versión de MATLAB
Se creó con R2021a
Compatible con cualquier versión
Compatibilidad con las plataformas
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Versión Publicado Notas de la versión