Challenge

Solving second order ODEs Python

Python for Mechanical Engineers

By Enos Leslie

Mechanical Engineer

23rd October 2024


AIM

This project aims to write a code in Python to simulate the behaviour of simple pendulum using ODE and animate it.


PROCEDURE

Initially, the math, matplotlib, numpy, and scipy modules were imported for their respective functionalities. Key input values such as b, g, l, and m were defined based on the provided data. An array representing the initial angle (theta) was created to specify the initial angular displacement and velocity. A time array was also generated, consisting of 100 equally spaced intervals between 0 and 20 seconds.

To solve the second-order ODE, a function named model was defined to incorporate the necessary matrix data. The second-order ODE was then solved using the odeint function with appropriate syntax, and the results were used to plot the graph showing the variation of angular displacement and velocity with respect to time.

For animating the pendulum's harmonic motion, a for loop was employed, along with a loop counter to track the iterations. The angular position values were stored in a variable called tempand updated in each iteration of the loop. During the animation, one end of the pendulum's string was fixed, while the other end moved according to the ODE solution. The motion was plotted for each time interval in the time span. animated with Kapwing online


PYTHON CODE


RESULTS


CONCLUSION

  • The plot above of angular displacement and angular velocity shows the pendulum's motion to be gradually decreasing. This is because of the damping effect which exponentially decreases the velocity of motion.

  • The Pendulum motion was animated successfully.


Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.