Skip to content
Snippets Groups Projects
Commit 16429e25 authored by cprutean's avatar cprutean
Browse files

Upload New File

parent 19adf9ca
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id:d05a32dc tags:
# Flight Plot
%% Cell type:code id:7947b211 tags:
``` python
"""
Form a plot the flight of a particle given initial velocity
and acceleration
"""
import math
import matplotlib.pyplot as plt # Import the plot package as plt
def distance(u,a,t):
"""
Function to calculate distance
"""
x = u*t + 0.5*a*t**2 # Calcualte distance
return x # Return distance
def main():
u = float(input("Initial velocity : "))
a = float(input("Acceleration : "))
maxTime = float(input("Maximum time : "))
plot_points = 100 # Number of point
increment = maxTime/plot_points # Increment between points
t_data = [] # lists to hold the data
x_data = []
for i in range(0,plot_points): # Start of loop
t = increment*i # Time
x = distance(u,a,t) # Get distance
t_data.append(t) # Append to t list
x_data.append(x) # Append to x list
plt.plot(t_data,x_data,"g") # Default plot in green
plt.title("Flight of particle") # Add title/lables
plt.xlabel("Time")
plt.ylabel("Distance")
plt.show() # show the actual plot
main()
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment