Project

ODE

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

def diffferentiate(initial,t,b,l,g,m):
	t1=initial[0]
	t2=initial[1]
	dt1=t2 #using the same transformation as shown in the tutorial video
	dt2=(-b/m)*t2-(g*math.sin(t1)/l)
	dt=[dt1,dt2]
	return dt

#damping
b=0.05
#length
l=1
#gravity acceleration
g=9.81
#mass
m=1

#initial[column 1 : displacement , column 2: angular velocity]
initial =[0,3]
t=np.linspace(0,20,200)
disp_velo=odeint(diffferentiate,initial,t,args=(b,l,g,m))
plt.plot(t,disp_velo[:,0],\'-\',label=\'displacement\')
plt.plot(t,disp_velo[:,1],\'--\',label=\'angular velocity\')
plt.legend()
plt.xlabel(\'time\')
plt.ylabel(\'displacement and angular velocity\')
plt.show()

y=disp_velo[:,0]
ct=100
for angle in y:
	x1=0
	y1=0
	x2=l*math.sin(angle)
	y2=-l*math.cos(angle)
	file=str(ct)+\'.png\'
	ct=ct+1
	plt.figure()
	plt.plot([-1.5,1.5],[0,0],linewidth=8)
	plt.plot([x1,x2],[y1,y2],linewidth=3)
	plt.plot(x2,y2,\'o\',markersize=15)
	plt.xlim([-1.5,1.5])
	plt.ylim([-1.5,1.5])
	plt.savefig(file)
	

\"\"code explanation :-

1. importing all the necessary files

2. creating a function which is evaluation the solution matrix as shown in the tutorial video and returning back the soln matrix

3. giving all the values of the variables present in the differential equation and giving the initial conditions

4. now plotting these and using odeint function

5. using the same image making code as used in Forward kinematics to get images and then stitching them up

errors which i faced were:

1. using the same code as forward kinematics i didnt notice the value of ct so it overrided the value

2. manipulating the value of y2 so that the pendulum comes downward else it was looking like linear inverted pendulum

youtube link :

https://youtu.be/xihZ3vVK2NM

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.