Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
plotting of graphs
#1
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?
Reply
#2
(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()
Reply
#3
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to plot 2 graphs in one figure? man0s 1 1,336 Apr-25-2022, 09:18 AM
Last Post: Axel_Erfurt
  Tuple Unpacking with graphs in matplotlib smw10c 2 5,942 Mar-23-2017, 05:13 PM
Last Post: smw10c

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020