Matlab Help Both in reality and in the formulation of Newton
Matlab Help!
Both in reality and in the formulation of Newtonian Friction, the density of the frictional medium (for a parachutist the medium is air) affects drag. Because a sky-dive begins at such a high altitude, the air density is different nearer the beginning of jump than nearer the end of the jump. The following table can be used to create a user-defined function that will calculate the approximate air density (kg/m^3) given an input of altitude (m). Use linear interpolation similar to the homework (User-defined functions). The following data can be used in the function file. Altitude, m Density, kg/m30 1.290610 1.2161219 1.1461829 1.0782438 1.0143048 0.9523658 0.8944267 0.839 STEPS 1. CREATE FUNCTION FOR AIR DENSITY USING LINEAR INTERPOLATION Create a function that, given the altitude of the parachutist, will return the air density found by linearly interpolating between the data from the above table (i.e. given one altitude at a time, return the linearly interpolated density value for that altitude). If you have data values d1 and d2 at two points x1 and x2, respectively, then the estimated d at a point x between x1 and x2 is given by: d = d1 + (d2–d1)*(x-x1)/(x2-x1) Test your function with a MATLAB script: (1) calculate density for sufficient altitudes between 0 and 4000 meters and (2) generate a clear plot of altitude (y-axis) versus air density (x-axis). Submit your plot and test code. Note: you may not use MATLABs built-in interpolation functions (e.g., interp1, etc.) 2. RUN SIMULATION WITH NEW FUNCTION FOR AIR DENSITY (RHO) Once your function works, change your parachute model to properly use the air density calculated by your function. Once again, make plots of height, velocity, and acceleration vs time using subplot. Submit copies of your code followed by your figures using the publish feature of MATLAB.
Solution
insert a module into the workbook by right-clicking on the workbook in the project window and selecting Insert>Module. Adding the module automatically opens a new code window.
We’ll need to give the function a name – I’ll call it “LinInterp”.
To perform the calculations, three arguments are required:
So we’ll enter those arguments, separated by commas. The first line of the function should look like this:
Function LinInterp(x, xvalues, yvalues)
Excel automatically adds the last line “End Function” when you type enter after the first line.
Gather the Inputs
According to the linear interpolation equation, to estimate y, we’ll need to gather a few values from our table of x- and y-data: x1, y1, x2, and y2.
We can use INDEX and MATCH to pull the values from the spreadsheet into the linear interpolation VBA function, but there’s a catch.
VBA doesn’t recognize these functions by themselves. In order to use them in our function, we have to tell VBA that they are worksheet functions. We can do that by preceding the function name with “Application.WorksheetFunction”.
So the line of code that extracts the x1 value from the table looks like this:
x1 = Application.WorksheetFunction.Index(xvalues, Application.WorksheetFunction.Match(x, xvalues, 1))
