Menu

Executive Programs

Workshops

Projects

Blogs

Careers

Placements

Student Reviews


For Business


More

Academic Training

Informative Articles

Find Jobs

We are Hiring!


All Courses

Choose a category

Mechanical

Electrical

Civil

Computer Science

Electronics

Offline Program

All Courses

All Courses

logo

CHOOSE A CATEGORY

Mechanical

Electrical

Civil

Computer Science

Electronics

Offline Program

Top Job Leading Courses

Automotive

CFD

FEA

Design

MBD

Med Tech

Courses by Software

Design

Solver

Automation

Vehicle Dynamics

CFD Solver

Preprocessor

Courses by Semester

First Year

Second Year

Third Year

Fourth Year

Courses by Domain

Automotive

CFD

Design

FEA

Tool-focused Courses

Design

Solver

Automation

Preprocessor

CFD Solver

Vehicle Dynamics

Machine learning

Machine Learning and AI

POPULAR COURSES

coursePost Graduate Program in Hybrid Electric Vehicle Design and Analysis
coursePost Graduate Program in Computational Fluid Dynamics
coursePost Graduate Program in CAD
coursePost Graduate Program in CAE
coursePost Graduate Program in Manufacturing Design
coursePost Graduate Program in Computational Design and Pre-processing
coursePost Graduate Program in Complete Passenger Car Design & Product Development
Executive Programs
Workshops
For Business

Success Stories

Placements

Student Reviews

More

Projects

Blogs

Academic Training

Find Jobs

Informative Articles

We're Hiring!

phone+91 9342691281Log in
  1. Home/
  2. ARAVIND M/
  3. Week 3 - Solving second order ODEs

Week 3 - Solving second order ODEs

SOLVING SECOND ORDER EQUATION USING PYTHONAIM               Using second ODE to describe the transient behaviour of a system of simple pendulum on python scripting.OBJECTIVE            In Engineering,…

  • PYTHON
  • ARAVIND M

    updated on 19 Apr 2021

SOLVING SECOND ORDER EQUATION USING PYTHON

AIM

               Using second ODE to describe the transient behaviour of a system of simple pendulum on python scripting.

OBJECTIVE

            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.

PROCEDURE

  • integrate module is imported for ODE equation by the syntax from scipy.integrate import odeint.
  • Then the variables and arguments are defined using function def mode1(theta,t,b,g,l,m):
  • Then the second ODE equation is breakdown into two single ODE, the first equation will give displacement and the second equation will give velocity.
  • Then the initial condition is defined by theta_0 = [ 0,3]
  • To obtain the smooth curve the points are divide into 150 points between 0 to 20 sec by t = np.linspace(0,20,150)
  • Then the function odeint are stored as theta.
  • The displacement values are extracted and stored in null array THETA3 using append command.
  • Then THETHA4 for loop is used to extract value from THETA3.

PROGRAM

# stimulation of pendulum
import math
import matplotlib.pyplot as plt 
import numpy as np 
from scipy.integrate import odeint

# Function
def mode1(theta,t,b,g,l,m):
	theta_1 = theta[0]
	theta_2 = theta[1]
	dtheta1_dt = theta_2
	dtheta2_dt = -(b/m) * theta_2 - ((g/l) * math.sin(theta_1))
	dtheta_dt  = [dtheta1_dt , dtheta2_dt]
	return dtheta_dt 
 # input

b = 0.05
g = 9.81
l = 1
m = 1

# initial condition 
theta_0 = [ 0,3]

# time point
t = np.linspace(0,20,150)

# solve ODE
theta =odeint(mode1,theta_0,t,args=(b,g,l,m))
a = theta[:,0] 
# plot
plt.figure(1)
plt.plot (t, theta [:,0], 'b--',label=r'$\frac{d\theta_1}{dt}=\theta_2 $')
plt.plot (t, theta [:,1], 'r--',label=r'$\frac{d\theta_2}{dt}=-1\frac{b}{m}\theta_2-\frac{g}{L}sin\theta_1 $')
plt.xlabel('time')
plt.ylabel('plot')
plt.legend([0,12])
plt.legend (loc='best')
plt.show()


#Animation
THETA3 = []
for theta3 in theta[:,0]:
	THETA3.append(theta3)

ct = 1
for THETA4 in THETA3:
	x0 = 0
	y0 = 0
	x1 = 1*math.sin(THETA4)
	y1 =-1*math.cos(THETA4)
	filename='pendulum%05d.png'%ct

	ct=ct+1
	plt.figure(2)
	plt.plot([-0.2,0.2],[0,0])
	plt.plot([x0,x1],[y0,y1])
	plt.plot(x1,y1,'-o')
	plt.xlim([-1.5,1.5])
	plt.ylim([-1.5,1])
	plt.title('Motion of Pendulum')
	plt.savefig(filename)
	plt.show()

ERROR

Invalid Syntax error for scipy.integrate.

Used syntax as from scipy.integrate import odeint

OUTPUT

TIME PLOT

ANIMATION

Leave a comment

Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.

Please  login to add a comment

Other comments...

No comments yet!
Be the first to add a comment

Read more Projects by ARAVIND M (61)

Week 6 - Data analysis

Objective:

DATA ANALYSIS USING PYTHON AIM             In this challenge, we have to do data analysis for a given data using python and extract the data and graph that user want by REPL method. REPL             REPL stands…

calendar

25 Apr 2021 01:56 PM IST

  • PYTHON
Read more

Week 5 - Curve fitting

Objective:

CURVE FITTING USING PYTHON AIM                In this challenge, we have to write a program for curve fitting using python. CURVE FITTING             Curve fitting is the process of constructing…

calendar

25 Apr 2021 01:25 PM IST

  • PYTHON
Read more

Week 3 - Solving second order ODEs

Objective:

SOLVING SECOND ORDER EQUATION USING PYTHONAIM               Using second ODE to describe the transient behaviour of a system of simple pendulum on python scripting.OBJECTIVE            In Engineering,…

calendar

19 Apr 2021 02:55 PM IST

  • PYTHON
Read more

Week 2 Air standard Cycle

Objective:

AIR STANDARD CYCLE USING PYTHON AIM             To write a program in python to solve the otto cycle and plot the graph. OBJECTIVE To solve different state variables in the otto cycle and plot p-v diagram. To calculate thermal efficiency for the given parameters in…

calendar

13 Apr 2021 01:33 PM IST

  • PYTHON
Read more

Schedule a counselling session

Please enter your name
Please enter a valid email
Please enter a valid number

Related Courses

coursecard

Core and Advanced Python Programming

4.8

30 Hours of Content

coursecard

Applying CV for Autonomous Vehicles using Python

Recently launched

21 Hours of Content

coursecardcoursetype

Mechanical Engineering Essentials Program

4.7

21 Hours of Content

coursecardcoursetype

Internal Combustion Engine Analyst course using Python and Cantera

4.8

22 Hours of Content

coursecard

Computational Combustion Using Python and Cantera

4.9

9 Hours of Content

Schedule a counselling session

Please enter your name
Please enter a valid email
Please enter a valid number

logo

Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.

https://d27yxarlh48w6q.cloudfront.net/web/v1/images/facebook.svghttps://d27yxarlh48w6q.cloudfront.net/web/v1/images/insta.svghttps://d27yxarlh48w6q.cloudfront.net/web/v1/images/twitter.svghttps://d27yxarlh48w6q.cloudfront.net/web/v1/images/youtube.svghttps://d27yxarlh48w6q.cloudfront.net/web/v1/images/linkedin.svg

Our Company

News & EventsBlogCareersGrievance RedressalSkill-Lync ReviewsTermsPrivacy PolicyBecome an Affiliate
map
EpowerX Learning Technologies Pvt Ltd.
4th Floor, BLOCK-B, Velachery - Tambaram Main Rd, Ram Nagar South, Madipakkam, Chennai, Tamil Nadu 600042.
mail
info@skill-lync.com
mail
ITgrievance@skill-lync.com

Top Individual Courses

Computational Combustion Using Python and CanteraIntroduction to Physical Modeling using SimscapeIntroduction to Structural Analysis using ANSYS WorkbenchIntroduction to Structural Analysis using ANSYS Workbench

Top PG Programs

Post Graduate Program in Hybrid Electric Vehicle Design and AnalysisPost Graduate Program in Computational Fluid DynamicsPost Graduate Program in CADPost Graduate Program in Electric Vehicle Design & Development

Skill-Lync Plus

Executive Program in Electric Vehicle Embedded SoftwareExecutive Program in Electric Vehicle DesignExecutive Program in Cybersecurity

Trending Blogs

Heat Transfer Principles in Energy-Efficient Refrigerators and Air Conditioners Advanced Modeling and Result Visualization in Simscape Exploring Simulink and Library Browser in Simscape Advanced Simulink Tools and Libraries in SimscapeExploring Simulink Basics in Simscape

© 2025 Skill-Lync Inc. All Rights Reserved.

              Do You Want To Showcase Your Technical Skills?
              Sign-Up for our projects.