#!/usr/bin/env pltthon3 # -*- coding: utf-8 -*- """ ENGG1811, Lecture 3, In-lecture project template """ # Import import math import matplotlib.pyplot as plt # Constants g = 9.81 # acceleration due to gravity in kg/s/s # Define a function to compute the free fall speed def free_fall(t,mass,drag): # To compute the freefall speed speed = g * mass / drag * (1 - math.exp(-drag*t/mass)) return speed # Problem parameters mass = 70 # Mass of the object in kg drag = 12.5 # Drag coefficient for air in kg/s # Test the function free_fall print('Speed at time 5',free_fall(5,mass,drag)) # Expect 32.4 print('Speed at time 10',free_fall(10,mass,drag)) # Expect 45.7 # To create a list of times # [0,0.5,1,1.5 ...,40] # range 0, 1, 2, 3, 4, ...,80 <-- given # time_list 0, 0.5, 1, 1.5, 2 40 <-- derive time_list = [] for k in range(81): time = k / 2 time_list.append(time) # To compute the list of speeds speed_list = [] for t in time_list: speed_at_time_t = free_fall(t, mass, drag) speed_list.append(speed_at_time_t) # To plot the graph # Note: You need to edit the line with plt.plot # To uncomment a block of text, use the Edit menu and choose # Comment/Uncomment fig1 = plt.figure() plt.plot(time_list,speed_list,'x') # <- need editing plt.xlabel('time [seconds]') plt.ylabel('speed [m/s]') plt.title('Free fall speed') #plt.grid() #plt.show()