#!/usr/bin/env pltthon3 # -*- coding: utf-8 -*- """ ENGG1811 lecture 7 Example: Simulate the parachutist's speed by formula """ # Import import para_ODE_ext_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 height0 = 4000 # Initial height in metres # Simulation parameters time_start = 0 time_end = 500 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, height_by_ODE_array = \ para_ODE.para_speed_height_ODE(time_array, mass, speed0, height0, air_drag_coeff, time_deploy, para_drag_coeff) # Plot the figure - Attempt 1 fig1 = plt.figure() plt.plot(time_array,speed_by_ODE_array,label = 'speed') plt.plot(time_array,height_by_ODE_array,label = 'height') plt.legend() plt.xlabel('time [seconds]') plt.ylabel('speed or height') plt.grid() plt.show() # Poor plot - can't see the features # Becaus height and speed have very different scale # %% # Alternative plotting method fig2, ax1 = plt.subplots() ax1.plot(time_array,speed_by_ODE_array, 'b') ax1.set_xlabel('time [seconds]') # Make the y-axis label, ticks and tick labels match the line color. ax1.set_ylabel('Speed [m/s]', color='b') ax2 = ax1.twinx() ax2.plot(time_array,height_by_ODE_array, 'r') ax2.set_ylabel('height [m]', color='r') # fig2.tight_layout() plt.grid() plt.show()