Challenge

Week 3 - Solving second order ODEs

PENDULUM DAMPING MOTION SIMULATION

for describing the damping oscillatory motion of the pendulum, we have to define parameters for this apparatus. along with this, we are taking few assumptions in order to accurately observe the effect of damping on oscillatory motion.

assumptions:

1) string is massless and of rigid length.

2) friction at hinge point is neglected

3) string is attached to the center of the pendulum.

4) The effects of pendulum radius is neglected against the length of string.

parametres:

1) length of string = 1 m

2) mass of pendulum = 1 kg

3) damping coefficient = 0.05

4) gravitational acceleration = 9.81 m/s^2

INITIAL CONDITIONS:

initially, the pendulum is in the middle of its trajectory and is given angular velocity. as the time elepses, it slowly dampens down and stops after some time. the parameters for simulation are described in question which are as below:

at time t = 0 sec

1) angular displacement = 0 rad

2) angular velocity = 3 rad/sec

the following python program relates to solving and plotting the required motion of pendulum with damping

INPUT(ODE SOLVER PROGRAM):

import math as M
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint

# parameters (SI system)

l = 1             # length of string in m
b = 0.05          # damping coefficient
m = 1             # mass of pendulum
g = 9.81          # gravitational accelaration

# initial conditions

ang_pos_initial = 0                        # initial angular position of pendulum
ang_vel_initial = 3                        # initial angular velocity of pendulum
state_zero = [0,3]                         # matrix defining boundry conditions for solution matrix
time_lapse = np.linspace(0,20,250)         # time span

# liniear transformation of system of ODEs

def linear_transform(S_mat,t,b,g,l,m):

	ang_pos  = S_mat[0]                                          # first element of solution matrix is angular position 
	ang_vel  = S_mat[1]                                          # second element of solution matrix is angular velocity

	d_dt_ang_pos = ang_vel                                      # defining first differential equation
	d_dt_ang_vel = -(b/m)*ang_vel - (g/l)*M.sin(ang_pos)        # defining second differential equation 

	d_dt_S_mat = [d_dt_ang_pos,d_dt_ang_vel]
	return(d_dt_S_mat)

# solving ODEs

S_mat =  odeint(linear_transform,state_zero,time_lapse,args = (b,g,l,m))   


# plotting trajectory of a pendulum and creating animation

collector = 1                     # initialising frame collector variable

for i in range(0,250):

	X = 1 * M.sin(S_mat[i,0])      # x-coordinate of pendulum trejectory
	Y = (-1) * M.cos(S_mat[i,0])   # y-coordinate of pendulum trejectory

	animation = str(collector) + '.png'      # initialising frame collection sequence for animation
	collector = collector + 1

	plt.figure()
	plt.plot([0,X],[0,Y])
	plt.plot(X,Y,'o', color='r',markersize= 20)
	plt.plot([-1.5,1.5],[0,0],linewidth= 5,color='k')
	plt.xlim([-2,2])
	plt.ylim([-2,2])
	plt.title('PENDULUM MOTION WITH DAMPING')
	plt.savefig(animation)                       # saving animation images
	











OUTPUT(animation link/youtube):

https://www.youtube.com/watch?v=dxQtobl1yyQ

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.

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.