- #1
BubblesAreUs
- 43
- 1
Homework Statement
Enter a minimum height and velocity into plot function and return a velocity-height plot.
Homework Equations
The Attempt at a Solution
Python:
# Find length of general list
n = len(K)
# Build a list for time [0,20] seconds ( Global)
time = n*[0.0]
# Acceleration of gravity
g = -9.80
def height(time, height0):
# Initialise H to be the same list size as time
H = n*[0.0]
for i in range(n):
H[ i ] = 0.5*-9.80*(time[ i ])**2 + height0
return H
def velocity(time,velocity0):
V = n*[0.0]
for j in range(n):
V[j] = -9.80*(time[j]) + velocity0
return Vdef plot(velocity0, height0):
# Plot the velocity V versus the height H
#
# Output: none
for k in range(n):
V = velocity(time[k],velocity0)
H = height(time[k],height0)
plot(V,H)
# Set Y-axis range
title('Plot of velocity versus height')
xlabel('velocity ( m/s)')
ylabel('height(m)')
grid('on')
show()
Traceback (most recent call last):
File "<pyshell#172>", line 1, in <module>
plot(100,400)
File "C:\Users\SILLYHEAD\Dropbox\MATH3511\Lab 1\Exercise7F.py", line 39, in plot
V = velocity(time[k],velocity0)
File "C:\Users\SILLYHEAD\Dropbox\MATH3511\Lab 1\Exercise7F.py", line 27, in velocity
V[j] = -9.80*(time[j]) + velocity0
TypeError: 'float' object has no attribute '__getitem__'
Last edited by a moderator: