Python Forum
plotting of graphs - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: plotting of graphs (/thread-15994.html)



plotting of graphs - mudezda1 - Feb-09-2019

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?


RE: plotting of graphs - scidam - Feb-10-2019

(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()



RE: plotting of graphs - mudezda1 - Feb-11-2019

(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.