Challenge

Week 3 - Solving second order ODEs

AIM:

To write a Python program which solves the equation of motion of a simple pendulum with damping.

OBJECTIVE:

  • To learn how to solve an Ordinary Differential Equation (ODE) using Python
  • To solve ODE of a simple pendulum that represents its equation of motion
  • To simulate the pendulum motion
  • Understand the importance behind motion study of a simple pendulum

Problem Statement

In Engineering, ODE is used to describe the transient behavior of a system. A simple example is a pendulum

The way the pendulum moves depends on the Newtons second law. When this law is written down, we get a second order Ordinary Differential Equation that describes the position of the "ball" w.r.t time.

Similarly, there are hundreds of ODEs that describe key phenomena and if you have the ability to solve these equations then you will be able to simulate any of theses systems.

Your objective is to write a program that solves the following ODE. This ODE represents the equation of motion of a simple pendulum with damping

In the above equation,

g = gravity in m/s2,

L = length of the pendulum in m,

m = mass of the ball in kg,

b=damping coefficient.

Write a program in Python that will simulate the pendulum motion, just like the one shown in the start of this challenge.

use,

L=1 metre,

m=1 kg,

b=0.05.

g=9.81 m/s2.

Simulate the motion between 0-20 sec, for angular displacement=0,angular velocity=3 rad/sec at time t=0.

When you do this you will get the position of the pendulum as a function of time. Use this information to animate the motion of the pendulum, as shown in the below figure.

Theory:-

An ordinary differential equation (ODE) is a differential equation containing one or more functions of one independent variable and the derivatives of those functions.

The ordinary differential equation under question here represents the equation of motion of a simple pendulum.

In fact, a simple pendulum consists of a mass m hanging from a string of length L and fixed at a pivot point P. So, in case it is tilted to an initial angle and released, the pendulum will swing back and forth with a periodic motion.

It lies on Newton’s second law and its study enables us to describe the simple harmonic motion or the theory of all oscillations.

Scientifically, pendulum finds its application in time-keeping even if nowadays it is getting substituted by atomic vibrations for the most accurate clocks. It is also used in the measurement of the acceleration due to gravity and also can be used the spinning of then earth.

where

g is the gravity in m/s^2

L is the length of the pendulum in m

m is the mass of the ball in kg

b is the damping coefficient

In order to write the Python program, the above equation is solved as following:

Input values:-

g=9.81 m/s2

l=1 m

b=0.05 m

m=1 kg

PROCEDURE:-

  • Initially we are going to import the “matplotlib.pyplot” , “math” , “scipy” and “numpy” library for the calculations.
  • Scipy library provides us a equation of the second order ODE to solve the theta value.
  • Then just input the given parameters are g, b, l and m to calculate the other parameters.
  • Using the calling function command we are going to call theta values.
  • And then using “numpy” command we provide the steps in the time.
  • Then plot the Time against Displacement graph.
  • For the motion of simple pendulum, first mention the co-ordinates of the pendulum at the start(x0, y0) and end(x1, y1).
  • Using the string and counter command we’ll give different png names and save all the png files.
  • For the Animation we use some other software to create the animation.

Program in Python:-

Output:-

Animation:-

Conclusion:-

  • Simulation of transient behavior of a Simple pendulum motion by solving second order differential equation.
  • Animation of the Simple pendulum is simulated.
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.