- Initially the constants are declared before moving onto the solver part in order to maintain the effectiveness of code.
- 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).
- 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.
- 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.
- 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.
- 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)
- 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
- After ending the for-loop, we increment the counter value to plus 1 for loop to run infinitely (motion of pendulum).
- 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.
- 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.
Iyer Aditya Ramesh (2022). Oscillatory motion of a Pendulum (https://www.mathworks.com/matlabcentral/fileexchange/94090-oscillatory-motion-of-a-pendulum), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!