Bottom Page

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 plotting of graphs mudezda1 Unladen Swallow Posts: 3 Threads: 2 Joined: Feb 2019 Reputation: 0 Likes received: 0 #1 Feb-09-2019, 06:32 PM (This post was last modified: Feb-09-2019, 06:58 PM by snippsat. Edited 2 times in total. Edit Reason: Added code tag ) I have an assignment where i have plot two physics equations named them as x and why, The only unkown is the angle, so i made a loop for the possible angles between 0 and 360 ```import math import numpy import matplotlib.pyplot as plt l= 1.5 m= 2.5 g= 9.81 d= 2.7 k= 9.08 alpha = 0 while (alpha<360): alpha = alpha + 1 angles = math.radians(alpha) x = 1-((2*l)/d)*math.sin(angles) y = ((m*g)/(k*d))*math.tan(angles) plt.plot(x,y) plt.show()```My question is how do i plot the two equations without knowing the value of theta? Is there anything wrong with my code? snippsat wrote Feb-09-2019, 06:58 PM:Added code tag in your post,look at BBCode on how to use. scidam  Posts: 426 Threads: 0 Joined: Mar 2018 Reputation: 60 Likes received: 61 #2 Feb-10-2019, 04:32 AM (Feb-09-2019, 06:32 PM)mudezda1 Wrote: My question is how do i plot the two equations without knowing the value of theta? I didn't see the value of theta... (Feb-09-2019, 06:32 PM)mudezda1 Wrote: Is there anything wrong with my code? You don't need `math` at all, since you are importing numpy. Also, you don't need to use loops. You need to create arrays of x- and y-values and plot the parametric graph. ```import numpy as np import matplotlib.pyplot as plt # define your constants here... angles = np.arange(360) / 180 * np.pi # step is one degree x = 1 - ((2 * l) / d) * np.sin(angles) y = ((m * g) / (k * d)) * np.tan(angles) plt.plot(x, y) plt.show()``` mudezda1 Unladen Swallow Posts: 3 Threads: 2 Joined: Feb 2019 Reputation: 0 Likes received: 0 #3 Feb-11-2019, 12:44 PM (Feb-10-2019, 04:32 AM)scidam Wrote: (Feb-09-2019, 06:32 PM)mudezda1 Wrote: My question is how do i plot the two equations without knowing the value of theta? I didn't see the value of theta... (Feb-09-2019, 06:32 PM)mudezda1 Wrote: Is there anything wrong with my code? You don't need `math` at all, since you are importing numpy. Also, you don't need to use loops. You need to create arrays of x- and y-values and plot the parametric graph. `import numpy as np import matplotlib.pyplot as plt # define your constants here... angles = np.arange(360) / 180 * np.pi # step is one degree x = 1 - ((2 * l) / d) * np.sin(angles) y = ((m * g) / (k * d)) * np.tan(angles) plt.plot(x, y) plt.show()` I sincerely thank you for your help. « Next Oldest | Next Newest »

Top Page

 Possibly Related Threads... Thread Author Replies Views Last Post Frequency Filter for wav file plotting in python manukanu 0 807 Dec-11-2018, 09:58 AM Last Post: manukanu Plotting climate data with NetCdf files for a specific region with coordinates fyec 3 739 Jun-27-2018, 12:34 PM Last Post: buran Plotting Graph jacky19971997 0 1,394 Jun-11-2017, 02:54 PM Last Post: jacky19971997 mcerp: error while plotting a histogram rakhmadiev 2 1,795 Apr-02-2017, 09:08 PM Last Post: rakhmadiev Tuple Unpacking with graphs in matplotlib smw10c 2 1,921 Mar-23-2017, 05:13 PM Last Post: smw10c plotting histogram vvv 1 1,215 Mar-10-2017, 11:47 PM Last Post: zivoni Issue plotting coordinates using Basemap kiton 5 3,934 Mar-09-2017, 07:33 PM Last Post: Larz60+

Forum Jump:

Users browsing this thread: 1 Guest(s)