Question

Write a program (python) to calculate and plot the position and the velocity of a linear piston connected to a crank through a connecting rod as a function of crank angle. The crank shaft is rotating at a constant angular velocity. The equation for the piston position and velocity is respectively given by ? = ? ???? + √? 2 − ? 2???2? ? = −? ? ???? − ? 2 ? ???? ???? √? 2 − ? 2???2? where r is the crank radius, l is rod length, θ is the crank angle with the piston axis, and ω is the crank angular velocity. Assume l = 15 cm, and ω = 100 rad/s and for r = 3 cm and 5 cm, plot the position and velocity from θ = 0 to 360 with 1 step size. Plot both in one figure with 2 subplots. Your plot should look like the following:

Homework 5: Write a program to calculate and plot the position and the velocity of a linear piston connected to a crank through a connecting rod as a function of crank angle. The crank shaft is rotating at a constant angular velocity. The equation for the piston position and velocity is respectively given r (u sure cose 12 -r2sin20 where r is the crank radius, l is rod length, θ is the crank angle with the piston axis, and ω is the crank angular velocity Assume 1 = 15 cm, and ω = 100 rad/s and for r-3 cm and 5 cm. plot the position and velocity from -0 to 360° with 1° step size. Note that 0 should be in radian if you are using math library for calculating sin(0) and cos(). Plot both in one figure with 2 subplots. Your plot should look like the following: Subplot for position Subplot for velocity Add plot labels and legends for different r values, and axes labels for each subplot. You need to search in the plot document for subplot options Challenge Modify your program to also find the maximum velocity of the piston and report the max velocity and corresponding crank angle to the user. Perform this search using a loop and your velocity data array. You should not use the built-in function for finding the maximum.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: In case of any queries, just comment in box I would be very happy to assist all your queries

for r = 0.05 cm

PYTHON CODE:

import math as m
import matplotlib.pyplot as p
l=0.15
w=100
r=0.05
k=0
b=0
maxm=0
a=[]
x=[]
v = []
while k<=360:
a.append(k)
x.append(r*m.cos(k)+m.sqrt((l**2)-r**2*(m.sin(k))**2))
v.append((-1*r*w*m.sin(k)) - ((r**2)*w*m.sin(k)*m.cos(k))/(m.sqrt(l**2-r**2*(m.sin(k))**2)))
k+=1
p.figure(1)
p.subplot(211)
p.plot(a,x)
p.xlabel("Angle")
p.ylabel("x")

p.subplot(212)
p.plot(a,v)
p.xlabel("Angle")
p.ylabel("v")
p.show()

#to calculate maximum velocity
maxm=v[0]
k=1
while k<len(v):
if(v[k]>maxm):
maxm=v[k]
b=k
k+=1
print("The maximum velocity is",maxm)
print("at angle",b)

0.20 0.18 0.16 0.14 0.12 0.10 250 350 200 300 150 100 50 Angle 250 350 300 150 100 200 50 Anglefor r = 0.03 m

PYTHON CODE:

import math as m
import matplotlib.pyplot as p
l=0.15
w=100
r=0.03
k=0
b=0
maxm=0
a=[]
x=[]
v = []
while k<=360:
a.append(k)
x.append(r*m.cos(k)+m.sqrt((l**2)-r**2*(m.sin(k))**2))
v.append((-1*r*w*m.sin(k)) - ((r**2)*w*m.sin(k)*m.cos(k))/(m.sqrt(l**2-r**2*(m.sin(k))**2)))
k+=1
p.figure(1)
p.subplot(211)
p.plot(a,x)
p.xlabel("Angle")
p.ylabel("x")

p.subplot(212)
p.plot(a,v)
p.xlabel("Angle")
p.ylabel("v")
p.show()

#to calculate maximum velocity
maxm=v[0]
k=1
while k<len(v):
if(v[k]>maxm):
maxm=v[k]
b=k
k+=1
print("The maximum velocity is",maxm)
print("at angle",b)

0.18 0.17 0.16 x 0.15 0.14 0.13 0.12 250 200 350 300 150 100 50 Angle 250 350 300 100 200 150 50 Angle

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Write a program (python) to calculate and plot the position and the velocity of a linear...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT