#!/usr/bin/env pltthon3 # -*- coding: utf-8 -*- """ ENGG1811 lecture 7 Example: Simulate the parachutist's speed by formula """ # Import import para_formula_lib as para_formula import para_ODE_lib as para_ODE import matplotlib.pyplot as plt import numpy as np # Problem parameters mass = 70 # Mass of the parachutist time_deploy = 6 # Time at which the parachute is deployed air_drag_coeff = 12.5 # Drag coefficient for air para_drag_coeff = 80 # Drag coefficient for parachute speed0 = 0 # Initial speed # Simulation parameters time_start = 0 time_end = 20 time_increment = 0.25 # Create a list of regularly spaced time instants # [0,0.25,0.5,0.75,...,20] # time_array = np.arange(time_start,time_end+time_increment/2, time_increment) # Use ODE to calculate the parachustist's speed # The function for calculating speed is in para_ODE_lib speed_by_ODE_array = para_ODE.para_speed_ODE(time_array, mass, speed0, air_drag_coeff, time_deploy, para_drag_coeff) # As a comparison, # use formula to calculate the parachustist's speed speed_by_formula_array = np.zeros_like(time_array) for k in range(0,len(time_array)): time = time_array[k] speed_para = para_formula.parachute(time,mass,air_drag_coeff,time_deploy,para_drag_coeff) speed_by_formula_array[k] = speed_para # Plot the figure fig1 = plt.figure() plt.plot(time_array,speed_by_ODE_array,label = 'ODE') plt.plot(time_array,speed_by_formula_array,label = 'Formula') plt.legend() plt.xlabel('time [seconds]') plt.ylabel('speed [m/s]') plt.show() # plt.savefig('para1.png')