Question

Use matplotlib to make a cycloid Please use python

Use matplotlib to make a cycloid
Please use python
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code in Python:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
# Config to put the animation on the jupyter notebook
plt.rcParams['animation.html'] = 'html5'
# radius of the circle
R = 1


def circle(a, b, r):
# (a,b): the center of the circle
# r: the radius of the circle
# T: The number of the segments
T = 100
x, y = [0]*T, [0]*T
for i,theta in enumerate(np.linspace(0,2*np.pi,T)):
x[i] = a + r*np.cos(theta)
y[i] = b + r*np.sin(theta)
return x, y

# Calculate the cycloid line
thetas = np.linspace(0,4*np.pi,100)
cycloid_x = R*(thetas-np.sin(thetas))
cycloid_y = R*(1-np.cos(thetas))
cycloid_c = R*thetas
fig = plt.figure()

lns = []
trans = plt.axes().transAxes
for i in range(len(thetas)):
x,y = circle(cycloid_c[i], R, R)
ln1, = plt.plot(x, y, 'g-', lw=2)
ln2, = plt.plot(cycloid_x[:i+1] ,cycloid_y[:i+1], 'r-', lw=2)
ln3, = plt.plot(cycloid_x[i], cycloid_y[i], 'bo', markersize=4)
ln4, = plt.plot([cycloid_c[i], cycloid_x[i]], [R,cycloid_y[i]], 'y-', lw=2)
tx1 = plt.text(0.05, 0.8, r'$ heta$ = %.2f $pi$' % (thetas[i]/np.pi), transform=trans)
lns.append([ln1,ln2,ln3,ln4,tx1])
plt.xlim(0,15)
plt.ylim(0,3)
plt.xlabel('x')
plt.ylabel('y')
plt.grid()
plt.axes().set_aspect('equal')
ani = animation.ArtistAnimation(fig, lns, interval=50)

ani.save('cycloid_ArtistAnimation.mp4',writer='ffmpeg')
ani.save('cycloid_ArtistAnimation.gif',writer='imagemagick')

ani

Screenshot of the code

import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation # Config to put the animation ontrans plt.axes().transAxes for i in range(len (thetas)): x,y - circle(cycloid_c[i], R, R) In1, plt.plot (x, y, g-,lw-2) 1n2,

Output:

θ=4.00 π 2 46 8 10 1214

Hope it helps :)

Add a comment
Know the answer?
Add Answer to:
Use matplotlib to make a cycloid Please use python
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
  • Subject : Visualizing Data in Python with Matplotlib Topic : Exploring Data Visually with Matplotlib using...

    Subject : Visualizing Data in Python with Matplotlib Topic : Exploring Data Visually with Matplotlib using Dictionaries Begin by reviewing the matplotlib documentation and the User Guide. Here we will make a histogram using some data from the Loan Stats Q1 2019 file. (Loan Stats Q1 2019 Download File Link : - https://www.lendingclub.com/info/download-data.action) Explore the user guide and then review this example : ( https://matplotlib.org/gallery/lines_bars_and_markers/categorical_variables.html) Question: Submit code demonstrating the following: Using the Loan Stats file, construct a dictionary containing...

  • Hi, I am having trouble with using the matplotlib function in python. A tutorial in this...

    Hi, I am having trouble with using the matplotlib function in python. A tutorial in this question and a lesson on how to use it would be great. Thanks so much. 2- Write a program using matplotlib that gives the following output Consider 100 points between [0,10] Fiqure 1 10 8 10 #Your program here:

  • IN PYTHON 3 GIVING THIS CODE %matplotlib inline import numpy as np import matplotlib.pyplot as plt...

    IN PYTHON 3 GIVING THIS CODE %matplotlib inline import numpy as np import matplotlib.pyplot as plt from sklearn import datasets N_samples = 2000 X = np.array(datasets.make_circles(n_samples=N_samples, noise=0.05, factor=0.3)[0]) plt.scatter(X[:,0], X[:,1], alpha=0.8, s=64, edgecolors='white'); Use Spectral Clustering to cluster the points and visualize your result

  • python 3.7 please help what command do I use to make a scatterpot in python?

    python 3.7 please help what command do I use to make a scatterpot in python?

  • Please write this in python codes(please use actual python file to write this and make a...

    Please write this in python codes(please use actual python file to write this and make a screenshot about the code without write them in txt file,thank you) Exercise 1 Consider the orthogonal transformation matnx S and vectors à and b 0.80 0.60 0.00 0.64 s-1-0.48 0.60 a=101 b= 0.360.48 0.80 a Construct the matrx S as a numpy array and caiculate its determinant. In [ ]: b. Verify that a b is invariant under the transformation S In : C....

  • must be python programming. consider function f(x) = sin(x) in the range of 0to pi. create...

    must be python programming. consider function f(x) = sin(x) in the range of 0to pi. create a python code to calculate f’ (derivative of f(x)) in this range and plot these points. calculate the error at all the discrete points. Please do not use Numpy you can use matplotlib

  • I have various sums that I've calculated from my dataframe and I want to use matplotlib...

    I have various sums that I've calculated from my dataframe and I want to use matplotlib and make pi chart of percentage of students with a particular nationality. for ex, totalStudents=(df.sum()) studentsSwiss=(df1.sum()) studentsIndian=(df2.sum()) studentsChinese=(df3.sum()) etc. And I want the pi chart to be in percentage. so take in those values convert to percentage of total students of that nationality. I'm using python. additional info: df is a dataframe that has a column that sums total Swiss, Indian, Chinese nationalities and...

  • This is a python matplotlib question. So it would be great if you could show me...

    This is a python matplotlib question. So it would be great if you could show me in python method. I have this loadtxt that asked to plot histogram of wind gusts(column 3) that lie in direction angle(column 2) from min angle to max angle inclusively. I don't know how to include min_angle and max_angle into my codes. Histogram of wind gust speeds As before the file akaroawindgusts.txt contains hourly maximum wind gusts speeds at the Akaroa Electronic weather station (EW)...

  • # python making a list of numbers i want to use python to make a list...

    # python making a list of numbers i want to use python to make a list of numbers like this A = [2,2,4,4,6,6,8,8,10,10.....................48,48,50,50] # it should be a total of 50 numbers long and contain 2 of each even number

  • (a) Use a computer program to plot the cycloid curve in the xy plane, given the...

    (a) Use a computer program to plot the cycloid curve in the xy plane, given the parametric equations: x(θ) = θ - sin θ y(θ) = 1 - cosθ (b) For a charge q moving in crossed (i.e., orthogonal) E and B fields, starting from rest at the origin, plot the kinetic energy as a function of time.

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