Homework answers / question archive /
AERO 3970  Aerospace Applications of MATLAB
Homework 3
Write a script file to perform the following c alculations
AERO 3970  Aerospace Applications of MATLAB
Homework 3
Write a script file to perform the following c alculations
Mechanical Engineering
Share With
AERO 3970  Aerospace Applications of MATLAB
Homework 3
Write a script file to perform the following c alculations. Output answers as indicated in each problem statement. All intermediary calculations should be suppressed with a semicolon. Save
the file as L astName_Hwk1.m. Remember to format your script file according to the guidelines described in the syllabus. Submit your script file and any supporting files (functions, data, etc.) as a single zipped folder via Canvas. I should be able to open your folder and run your script without any errors.
1. Standard Atmosphere Interpolation [10 Pts]
The relation between geopotential _{h }and geometric altitude _{hG }is given by
h = r hG where r = 6.356733 × 106 m (1) r +h_{G}
Recall, that the standard atmosphere is divided into a series of gradient and isothermal regions. (See Chapter 3 of Introduction to Flight by John D. Anderson for a review of the standard atmosphere). The first gradient region extends over the range 0 km ≤ _{h }_{≤ }11 km. Over this range the temperature, pressure, and density are governed by
T =T_{s }+a(h − h_{s}^{) }(2)
ρ T −{[g0/(aR)]+1}
= (3) ρs Ts
p T −g0/(aR)
= (4) ps Ts
where a = −6.5 × 10^{−3 }Km^{−1}, h_{s }= 0 km, T_{s }= 288.16 K, ρ_{s }= 1.2250 kgm^{−3}, p_{s }= 1.01325 × 10^{5 }Pa, _{R }_{= }287 Jkg^{−1 }K^{−1}, and _{g0 }= 9.8 ms^{−2}. The next isothermal region is defined over the range 11 km ≤ _{h }_{≤ }25 km. Here the temperature, pressure, and density are governed by
T =T1 (5)
ρ
= exp {−[g0/(RT)](h − h1)} (6) ρ1 p
= exp {−[g0/(RT)](h − h1)} (7) p1
where _{h}1 = 11 km, _{T}1 = 216.66 K, _{p}1 = 2.26 × 10^{4 }Pa, and ρ1 = 0.367 kgm^{−3}.
 Write a function that will calculate and return the temperature, pressure, and densitygiven a geometric altitude, _{hG}. (Bonus [1 Pt]: Construct the function in such a way that a vector of altitudes of any length can be passed and the corresponding arrays of T, _{p}, and ρ are returned.) With your function, calculate the values of _{T}, _{p}, and ρ at h_{G }_{= }1250, 8562, 12324, and 19956 m.
Auburn University, Department of Aerospace Engineering
AERO 3970  Homework 3 Fall 2021
 Based on the table lookup example that was covered in class, create a function thataccepts a vector of _{x }values, a matrix of _{y }values where each column corresponds to a different function and each row corresponds to an _{x }value, and a vector of query points. The function should return an array of interpolated values at the query points using linear interpolation.
 Read in the included standard atmosphere .csv file using dlmrea_{d}_{ }or csvrea_{d}. The data is arranged such that the first column contains the geometric altitude in km, the second temperature in K, the third pressure in Pa, and the last the density in kgm^{−3}. Using this data and the function from part (b) interpolate the values of _{T}, _{p}, and ρ at the geometric altitudes given in part (a).
 Use interp_{1}_{ }and the data read in part (c) to obtain interpolated values for _{T}, _{p}, and ρ at the same altitudes using the ’pchip’ method.
 Output well formatted, clean tables of the results. You should output three tables. Oneeach for _{T}, _{p}, and ρ with 4 row labels indicating the altitude and 4 column labels. Format the numbers in scientific notation with 4 decimal points (this is equivalent to
format shortE).
 Thought Question: In a short code comment, which interpolation method was the most accurate as compared to the direct calculation? Why?
2. Search Algorithm Comparisons [5 Pts]
In class, we mentioned that there are several ways to search for a value within an array. For interpolation we desired the index of the element whose value directly preceded the requested interpolation point. There are two basic types of searches that are commonly used. Your task is to implement each type of search described below and compare the time it takes to find a set of requested values.
 Linear Search: For the linear search, you should iterate over each element in the array comparing the value to the desired value..
 Read in the provided vector using loa_{d}. The variable contained in the .mat file is named vec.
 Implement a linear search to find the following values: 313176, 1403219, 2303140,3949712. Start the search from scratch for each value. Also, output the index at which each value was found in a clearly labeled statement.
 Use tic and toc to determine how long it takes to find all of the requested values and output the result to the command window.
 Binary Search: A binary search works off the assumption that the data is sorted from lowest to highest. Each iteration within the search, compares the median value to the requested value. If the median is less than the requested, then the requested value lies in the upper half of the original range and the range is reset with the median as the lowest value. If the median is greater than the requested, then the requested value lies in the lower half of the original range and the range is reset with the median as the highest value. If the median is equal to the requested, then the location has been found. This series of split, compare, reduce is repeated until the requested value is found.
Auburn University, Aerospace Engineering Department
AERO 3970  Homework 3 Fall 2021

 Use the same vector that was loaded in part (a)
 For each requested value, implement a binary search to determine its location.
 Use tic and toc to time how long it takes to find all of the requested values and output the result to the command window.
 fin_{d}: Use the builtin MATLAB function find to determine the location of the values in part (a). Determine the total time to find all four values and print the locations in a clearly labeled statement. (Hint: Each method should report the same location for a given value. If not, something is wrong.)
 Thought Question: In a code comment, which method was faster? Why?
Auburn University, Aerospace Engineering Department