Book
Advanced Engineering Mathematics
Author
Erwin Kreyszig
Edition
8th Edition
print 'Please specify the intial position'
print 'vertucak upright position'
offset=int(raw_input('Enter the intial angle now:'))
tfinal=int(raw_input('Please enter the duration of simulation'))
print 'I am working....'
theta=pi-offset
thetadot=0
dt=0.2
t=0
tf=tfinal
print 'Watch the graphics screen'
clf()
h1=axes([0.55,0.1,0.4,0.3])
axis([0,tf,-4,4])
xlabel('time')
ylabel('dispalcement')
xlim(0,130)
ylim(-4,4)
plot([],[],'.')
h2=axes([0.55,0.55,0.4,0.3])
axis([0,tf,-4,4])
xlabel('time')
ylabel('velocity')
xlim(0,30)
ylim(-4,4)
plot([],[],'.')
h3=axes([0.1,0.1,0.4,0.4])
axis([-pi,pi,-4,4])
axis('scaled')
xlabel('displacement')
ylabel('velocity')
xlim(-4,4)
ylim(-4,4)
plot([],[],'.')
h4=axes([0.1,0.55,0.4,0.4])
axis([-2,2,-2,2])
xlim(-2,2)
ylim(-2,2)
#axis('square')
data=[[0,0],[-1.8,0]]
phi=0
R=[[cos(phi),-sin(phi)],[sin(phi),cos(phi)]]
data=dot(R,data)
plot(data[0,:],data[1,:],linewidth=3)
plot(0,0,'o')
plot([],[],'.')
while (t<tfinal):
t=t+dt
theta=theta+thetadot*dt
thetadot=thetadot-sin(theta)*dt
R=[[cos(theta),-sin(theta)],[sin(theta),cos(theta)]]
datanew=dot(R,data)
plot(datanew[0,0],datanew[1,0])
plot(datanew[0,:],datanew[1,:])
plot(theta,thetadot)
plot(t,theta)
plot(t,thetadot)
show()
Solution by:
- telugupraveenkumar,student,SNIST
