Question
CSS - HW: Arrays You will write a program that calculates the velocity of a skydiver as a function of time. The main program will
CSS - HW: Arrays
You will write a program that calculates the velocity of a skydiver as a function of time. The main program will include a loop that allows you to enter in the specifications for more than one jump.
Work Items
- Write the program described below. Submit the single Java file (i.e., ".java" text file) that contains your program:
- Please submit only a single Java file via Canvas. Do not email your instructor your work.
- Name your Java file HW_Arrays.java. You must name your file this way.
- Note that by requiring you name your Java file HW_Arrays.java, it means that the public class that is in that file has to be named HW_Arrays.
Introduction to the Problem
If you had physics before, you will recognize the problem of finding the velocity of a skydiver as similar to that of the fall of an object under the influence of gravity. However, unlike the case studied in most introductory physics courses, where air resistance is neglected, in the case of a skydiver, you cannot neglect air resistance. Thus, Newton's Second Law has two forces you have to account for:
Ftot=ma=FgravityFdrag
where m is the mass (kg) and a is the acceleration (m/s2) of the skydiver. Note, in this and subsequent equations, we will assume that the positive x-direction (and thus the positive velocity and acceleration) points down towards the ground.
(As an aside, in a vacuum where we can neglect air resistance and gravity is the only force acting on the skydiver, we can neglect Fdrag and the above simplifies:
Ftot=ma=Fgravity=mgma=mga=g
Meaning, the acceleration of the skydiver (a) equals the acceleration of gravity at the surface of the Earth (g=9.81 m/s2). Which makes sense :).)
In the case where we have air resistance, in general we cannot solve for acceleration (and thus velocity) by hand, using just algebra or calculus. The reason is because air resistance is generally a function of velocity:
Fdrag=12CAav2
where C is the drag coefficient (unitless), A is the cross-sectional area (m2), a is the air density (kg/m3), and v is the velocity (m/s). So, we have to solve this using a computer. How do we do this? Going back to Newton's Second Law, we can plug in for Fdrag to find:
Ftot=ma=FgravityFdrag=mg12CAav2
a=gCaA2mv2
Note this means that the acceleration at any given moment in time is determined by the velocity at any given moment in time. That is:
a(t)=gCaA2mv(t)2
(assuming g, C, a, A, and m are constant with time). But the velocity at any given moment in time depends on the acceleration a small bit of time before the current time. And that past acceleration depends on the past velocity, which in turn depends on the acceleration before that. And so on.
Here's another way to think of the problem. The velocity at time t, in general, can be given as:
v(t)=v(tt)+a(tt)t
where t is a small bit of time. Applying this to the specific case of the skydiver, we can substitute in for a(tt)using the a(t) equation before it, namely:
v(t)=v(tt)+(gCaA2mv(tt)2)t
But what this equation tells us is that the velocity at time t depends on the velocity at time tt. And the velocity at time tt depends on the velocity at time t2t, and so on. This is why we need to use the computer, because in order to calculate the velocity at the current time t you have to first calculate the velocities at all intermediate bits of time prior to t. Note that if you didn't follow this derivation, that's okay: to write the program, all you need to use is this last equation above.
(As an aside, remember that notation like v(tt)2 does not mean "the velocity times the quantity t minus t, all squared" but rather "the square of the velocity evaluated at time tt." That is to say, the notation v(t) is not "vtimes t" but "the function v evaluated at t.")
Program Description
Your program should ask you to enter in the mass, cross-sectional area, and drag coefficient of the skydiver. Your program should also ask how long do you want to calculate the dive out to and what your timestep (t) will be. You can assume the density of air is 1.14 kg/m3 and gravitational acceleration is 9.81 m/s2. (Density of the atmosphere value from https://answers.yahoo.com/question/index?qid=20110201191027AADvsI0 (Links to an external site.)Links to an external site., accessed September 6, 2014.)
As your program does its calculations, it should save the time and velocities in an array (i.e., in two separate one-dimensional arrays, one for time and the other for velocities). One you have calculated all these values, write the output to a file. The file should have two columns, the first being the time (t) and the second being the velocity (v(t))at that time. Please separate the values in each column (along a given row) by a comma (e.g., "0.200, 1.9616"). If you do so, you will create the comma-separated value (CSV) file I mentioned earlier that Excel can read in without difficulties: Importing a delimited text file into Excel usually means opening Excel and then choosing "Open" from the File menu. Excel should detect what kind of file it is and try to parse it into a spreadsheet grid format. Your program, then, should also prompt you for the output filename. (Note, you actually don't need arrays to solve this homework, but arrays are used in scientific computing all the time, and by asking you to write the code in this way, I'm hoping you'll get some practice manipulating arrays.)
While the full output will go to a file, you should write out a few values to screen, so you can see how you're doing. Make that diagnostic output match this example console output (when the parameter values are as shown):
Enter the mass of the skydiver (kg): 80 Enter the cross-sectional area of the skydiver (m^2): 1.035 Enter the drag coefficient of the skydiver: 0.581 Enter the ending time (sec): 16 Enter the time step (sec): 0.1 Enter the output filename: soln.csv Writing out file. Here are the first few lines: 0.100, 0.981 0.200, 1.9616 0.300, 2.9409 0.400, 3.9182 0.500, 4.8927 0.600, 5.8634 0.700, 6.8297 0.800, 7.7907 0.900, 8.7457 Enter another dive? (y/[n]): n
For the case whose plot you turn in, you'll want to calculate a substantial number of timesteps, out at least to t=16 sec. Use a t=0.1 sec, a mass of 80 kg, cross-sectional area of 1.035 m2, and a drag coefficient of 0.581 (drag coefficient is unitless). (Values for the skydiver from https://answers.yahoo.com/question/index?qid=20110201191027AADvsI0 (Links to an external site.)Links to an external site., accessed September 6, 2014.) Your initial velocity, i.e., v(t=0 sec), should be 0 m/s. By the way, when using these settings, your graph should show the skydiver achieves terminal velocity; at a certain time, the velocity shown on the graph should level off. If you aren't getting this behavior (or the sample output given above), something's wrong.
Finally, there should be at least one method that you write that can be used to provide output for tracing variables: The method should be called test-something, e.g., testVariableValues. Somewhere in your program, there should be a call to that method. In the code you submit, that call should be commented out, but I should be able to find it.
(If you're curious: This doesn't contribute to your grade, but try one case where t is quite a bit larger (and all the other parameters are the same), say t=5 sec. What happens to your solution? Does this make physical sense? Any thoughts on why this occurs? We'll talk about this briefly in lecture. One hint: What you see is a classic example of what in scientific computing is called "numerical instability.")
Frot ma Fgravity Fdrag (m/s2) (g = 9.81 m/s *)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started