AER E 1600 - Lecture 6 Study Notes
Iowa State University Aerospace Engineering AER E 1600 - Lecture 6
Overview of the Lecture
- Introduction to Programming with Python focusing on Numerical Integration of Ordinary Differential Equations (ODE) using Euler's Method.
- Instructor: Carolyn Riedel
Key Topics Covered
- Vector Math with Numpy and Lists
- Graphing using Matplotlib
- Installation of the units toolbox Pint
- Understanding numerical integration
- Importance of numerical integration in programming
- Overview of numerical integration of ODE by Euler’s Method
Vectors: Fundamental Concepts
Definition of Vectors
- Vectors are mathematical symbols used for quantities that possess both magnitude and direction.
- Example: A force has both a magnitude (how much force) and a direction (in which direction it is applied).
- In structural design, it's crucial to consider both magnitude and direction to ensure adequate support and stability.
Scalars vs. Vectors
- Scalar quantities only have magnitude (e.g., temperature, mass).
- Importance of Vectors:
- Understanding vectors is essential in fields like physics and engineering where direction plays a crucial role in analysis and design.
Notation for Vectors
Different Representations
- A vector F can be denoted in various ways including:
- The notation can vary depending on the field being discussed.
Magnitude and Components of Vectors
Magnitude Calculation
- The magnitude of the vector F can be calculated using the formula:
F=extsqrt(F<em>x2+F</em>y2+Fz2) - Alternatively, if the magnitude and angle at which the force is applied are known, the components can be derived:
- Fx=Fimesextcos(heta)
- Fy=Fimesextsin(heta)
Practical Applications in Class
Hands-On Exercises
- Calculate the vector between the points (3,5,7) and (2,6,3).
- To find the magnitude of this vector, use:
extmagnitudeofvector(a,b,c)=extsqrt(a2+b2+c2) - Find the direction of this vector (i.e., unit vector).
Using Numpy for Vector Calculations
Linspace Function
- Function:
np.linspace(start, stop, num_points) - generates evenly spaced values between the start and stop.
- Exercise: Create an array from -1 to 3 with 1000 points and check the length of the generated array.
Arange Function
- Function:
np.arange(start, stop, step) - generates values starting at a point, stopping before another, with a specified step.
- Exercise: Create an array from 0 to 4 with a step size of 0.01, and determine the length of the array.
Plotting with Matplotlib
Introduction to Matplotlib
- Library Use: Matplotlib is a library for creating static, animated, and interactive visualizations in Python.
- Pyplot:
- The
pyplot module is used for plotting commands.
Basic Plotting Commands
Standard Plot Structure
from matplotlib import pyplot as plt
import numpy as np
- Create an array and corresponding y-values to plot, for example:
x = np.arange(0, 50.5, 0.5)
y = 5 * x + 10
plt.plot(x, y)
plt.title("PyPlot Example X vs Y")
plt.xlabel('X')
plt.ylabel('Y')
Review of Plotting Commands
- Steps to Plot:
- Start the code with importing libraries.
- Plot the data using
plt.plot(x, y). - Add a title with
plt.title(). - Label the axes with
plt.xlabel() and plt.ylabel().
Projectile Motion and Plotting
- Projectile Path Equation:
- The path of a projectile is determined by:
x=V<em>0imesextcos(heta)imesty=V</em>0imesextsin(heta)imest−21gt2
- Variables defined:
- V0 - initial velocity
- heta - launch angle
- g - acceleration due to gravity (9.8 m/s²)
- t - time
- Exercise: Graph the trajectory of a cannonball shot at a 30° angle with an initial velocity of 125 m/s, over 10 seconds.
Installing and Using Pint for Unit Conversion
Introduction to Pint
- Pint: A Python package for unit conversion.
- Installation Steps:
- Open Anaconda Prompt.
- Type
conda install -c conda-forge pint. - Confirm installation by typing 'y'.
Unit Registry in Pint
- Pull out the unit registry and assign it to
ur. - You can add units and convert them easily.
- Example of unit conversion:
- To extract the number without the units, use the
.magnitude method.
In-Class Unit Conversion Exercise
- Determine the force of an object with a mass of 40 lbs under acceleration due to gravity, which is 32.2 ft/s².
- Print the results in both pounds and Newtons.
Additional In-Class Exercise
- Find the force of an object with a mass of 1.24 slugs under the same gravitational conditions.
- Print the results as previously.
Understanding Numerical Methods
Definition and Applications
- Numerical methods provide approximations for complex mathematical procedures, facilitating calculations in cases where closed-form solutions are unattainable.
- Applied in programming environments to solve ordinary differential equations (ODEs).
Calculating Savings Over Time
- The change in money over time in a savings account can be modeled by the differential equation:
dtdM=rimesM+s
where:
- $M$ = dollar amount in the account (in units of dollars)
- $r$ = interest rate (in units of per year)
- $s$ = savings rate (in units of dollars per year)
Euler's Method
Overview
- Definition: A numerical procedure for approximating the solutions to ODEs by breaking them down into small, finite intervals.
- In the equation representation, use extd symbolically replaced with extδ to indicate usage in the finite space.
- Modified equation:
δM=(rimesM+s)imesδt
Example Calculation Using Euler's Method
Given Values
- Interest rate (r) = 0.02
- Initial savings amount ($) = $10,000
- Savings rate (s) = $5000/year
- Time step (δt=0.1)
Stepwise Calculation
| t | $ (M)$ | Calculation |
|---|
| 0 | 10000 | ($0.02 imes 10000 + 5000) imes 0 = 0 |
| 0.1 | 10520 | ($0.02 imes 10000 + 5000) imes 0.1 = 520 |
| 0.2 | 11041.04 | … |
| 0.3 | 11563.12 | … |
Coding Euler's Method
Steps to Implement
- Initialize starting values.
- Create an array for time (start at 0, to 1, step size = 0.01).
- Create an empty array to store generated values.
- Loop through calculations to determine δM.
- Store results and plot against time.
Thrust Specific Fuel Consumption (TSFC)
Definition and Importance
- TSFC measures the rate of fuel consumption relative to thrust and is crucial for evaluating rocket performance.
- Unit: extlb/extlbfimesexts
Change in Rocket Mass Over Time
Fundamental Equation
- The rate of change in the rocket mass can be expressed as:
dtdm=−extTSFCimesT
where:
- extTSFC = Thrust Specific Fuel Consumption
- T = Thrust of the rocket (N or lbf)
Euler’s Method Application
- This can be expressed as: (oldsymbol{δm} = (− ext{TSFC} imes T) imes oldsymbol{δt}
Example Calculation - Fuel Burnout
- Thrust = 175,700N
- Mass of Propellant = 133,971 kg
- Mass of Structure = 6,676 kg
- Mass of Payload = 1,900 kg
- TSFC = 0.0003 lb/lbf/s
- Time step = 0.001 s$$
Steps to Calculate Time Until Fuel Runs Out
- Use Euler's Method to iterate through time steps until the fuel is exhausted.
References
- Resource links include documentation of Euler's Method and additional Python learning resources such as LinkedIn Learning, w3schools.com, and PyNative.