Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

  1. Write the program described below. Submit the single Java file (i.e., ".java" text file) that contains your program:
    1. Please submit only a single Java file via Canvas. Do not email your instructor your work.
    2. Name your Java file HW_Arrays.java. You must name your file this way.
    3. 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:

image text in transcribedFtot=ma=FgravityFdrag

where image text in transcribedm is the mass (kg) and image text in transcribeda is the acceleration image text in transcribed(m/s2) of the skydiver. Note, in this and subsequent equations, we will assume that the positive image text in transcribedx-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 image text in transcribedFdrag and the above simplifies:

image text in transcribedFtot=ma=Fgravity=mgma=mga=g

Meaning, the acceleration of the skydiver (image text in transcribeda) equals the acceleration of gravity at the surface of the Earth image text in transcribed(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:

image text in transcribedFdrag=12CAav2

where image text in transcribedC is the drag coefficient (unitless), image text in transcribedA is the cross-sectional area image text in transcribed(m2), image text in transcribeda is the air density image text in transcribed(kg/m3), and image text in transcribedv is the velocity image text in transcribed(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 image text in transcribedFdrag to find:

image text in transcribedFtot=ma=FgravityFdrag=mg12CAav2

image text in transcribeda=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:

image text in transcribeda(t)=gCaA2mv(t)2

(assuming image text in transcribedg, image text in transcribedC, image text in transcribeda, image text in transcribedA, and image text in transcribedm 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 image text in transcribedt, in general, can be given as:

image text in transcribedv(t)=v(tt)+a(tt)t

where image text in transcribedt is a small bit of time. Applying this to the specific case of the skydiver, we can substitute in for image text in transcribeda(tt)using the image text in transcribeda(t) equation before it, namely:

image text in transcribedv(t)=v(tt)+(gCaA2mv(tt)2)t

But what this equation tells us is that the velocity at time image text in transcribedt depends on the velocity at time image text in transcribedtt. And the velocity at time image text in transcribedtt depends on the velocity at time image text in transcribedt2t, and so on. This is why we need to use the computer, because in order to calculate the velocity at the current time image text in transcribedt you have to first calculate the velocities at all intermediate bits of time prior to image text in transcribedt. 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 image text in transcribedv(tt)2 does not mean "the velocity times the quantity image text in transcribedt minus image text in transcribedt, all squared" but rather "the square of the velocity evaluated at time image text in transcribedtt." That is to say, the notation image text in transcribedv(t) is not "image text in transcribedvtimes image text in transcribedt" but "the function image text in transcribedv evaluated at image text in transcribedt.")

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 image text in transcribed(t) will be. You can assume the density of air is image text in transcribed1.14 kg/m3 and gravitational acceleration is image text in transcribed9.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 image text in transcribed(t) and the second being the velocity image text in transcribed(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 image text in transcribedt=16 sec. Use a image text in transcribedt=0.1 sec, a mass of 80 kg, cross-sectional area of image text in transcribed1.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., image text in transcribedv(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 image text in transcribedt is quite a bit larger (and all the other parameters are the same), say image text in transcribedt=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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And SQL For DB2

Authors: James Cooper

1st Edition

1583473572, 978-1583473573

More Books

Students also viewed these Databases questions