Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please code on glowscript.org and post pictures of code, outputs, and pencil and paper work. Please complete the full assignment. Using if Statements It often

Please code on glowscript.org and post pictures of code, outputs, and pencil and paper work. Please complete the full assignment.
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Using if Statements It often happens that I want my code to do a thing but I don't want it to do it right now. For this purpose, all programming languages feature logical statements. This idea is simple, if this condition is met, do this, if not, do something else. Here is an example of logical code in VPython: Note the obligatory indentation here. - 6: note the double equal sign for "is equal" - 5 executed if a is equal to b 1 - S'a also executed if a is equal to b a > 10: . a not equal to b but greater than 10 # any other case If I place this logic inside of a while loop, it will be checked over and over with each tick of the clock. What if I wanted to constantly check to see if a falling object had reached the ground yet? The Basic Free Fall Code Here it is: Motion Parameter vea(0, 10,0) vec (0.-9.0 Don't bother to run it. It creates no output whatsoever. In fact, I have stripped all of the fun from this code by not creating any 3D objects at all. It just happily computes and then stops. From top to bottom we see some familiar things. First, the acceleration due to gravity appears as a constant but further along is used as the y-component of the acceleration vector. The velocity v and the position r are also defined as vectors with arbitrary initial values in the y-components. The while loop begins as usual except that it is designed to run as long as t > -1 is true. This statement, however, is always true, so our while loop will run forever! Notice, however, the final two lines of this code, it r. y y !:, which checks at every step the y-component of the position r and compares it to the value of yf. If we think if yf as the final y position, this code will calculate free-fall motion starting at 5 m with an initial upward velocity of 10 m/s. The calculation continues, upward and downward, until the position becomes 0 m and the it statement allows the break command to stop the code dead. Graphical Analysis In our study of kinematics, we have noted that a lot of useful information about motion can be gleaned from motion graphs such as stand ou... VPython has built in features that allow us to make graphs of any quantities we wish. The syntax is remarkably simple. In order to make graphs of position and velocity, we need to initiate the graphical curve routine for each, like this: gourve (color color.red e color color blue these lines need to be placed early in the code in order to initialize our graphs. Later in the code we begin to calculate positions and velocities in our while loop. All we need do is add: to the white loop. Each time the loop goes round, it will add the vertical position, vertical velocity and time to the graph. Ada these lines to the basic free-fall code provided and see what the result looks like. You should get a very pleasing graph that matches the physical motion that is being calculated Change the initial velocity and initial position to arbitrary but sensible values and run your code again. Paste your program A Big Task It's now time to use all of the techniques and skills that you have learned thus far to produce a final product more or less on your own. You will modify the basic code presented in the beginning of this lab to solve free-fall problems and create a pleasing animation to boot. Feel free to get creative with the way things look. VPython has lots of features that we haven't used yet, but are easily implemented and can make your code more fun/interesting/impressive. You can read about them here Begin with the base code and eliminate the graphs. Your code should accomplish the following tasks: Create a 3D object that will free-fall. Create a 3D box that will serve as the "ground" Prompt the user for the initial position, initial velocity and final position Add in any way) an indicator that the velocity of the object is positive or negative. (i.e. an arrow, a color, a label) Animate the motion until it reaches the final position. Output the final velocity. Output the total time Output the distance traveled. This is not a task that we have done before, so give it some thought. This may be the first time working with VPython that you get a lot of error messages. Don't get discouraged. There are a lot of little details to pay attention to and it is hard, if not impossible, to get it right on the first go. Remember to make your changes one at a time and run your code often to test your progress. Choose some reasonable initial conditions and solve the problem with pencil and paper. Once you know the answers, run the code to check. CHALLENGE: Modify your code so that the ball bounces instead of stopping. By the way, in your code does it look like the ball is going into the floor? I bet you can fix that. In your your OneDrive doc, paste an image of your pencil and paper solution Paste a screenshot of your final output into your OneDrive doc. Paste your final program into your OneDrive doc. Submit your OneDrive doc to the assignment on BBLeam. Using if Statements It often happens that I want my code to do a thing but I don't want it to do it right now. For this purpose, all programming languages feature logical statements. This idea is simple, if this condition is met, do this, if not, do something else. Here is an example of logical code in VPython: Note the obligatory indentation here. - 6: note the double equal sign for "is equal" - 5 executed if a is equal to b 1 - S'a also executed if a is equal to b a > 10: . a not equal to b but greater than 10 # any other case If I place this logic inside of a while loop, it will be checked over and over with each tick of the clock. What if I wanted to constantly check to see if a falling object had reached the ground yet? The Basic Free Fall Code Here it is: Motion Parameter vea(0, 10,0) vec (0.-9.0 Don't bother to run it. It creates no output whatsoever. In fact, I have stripped all of the fun from this code by not creating any 3D objects at all. It just happily computes and then stops. From top to bottom we see some familiar things. First, the acceleration due to gravity appears as a constant but further along is used as the y-component of the acceleration vector. The velocity v and the position r are also defined as vectors with arbitrary initial values in the y-components. The while loop begins as usual except that it is designed to run as long as t > -1 is true. This statement, however, is always true, so our while loop will run forever! Notice, however, the final two lines of this code, it r. y y !:, which checks at every step the y-component of the position r and compares it to the value of yf. If we think if yf as the final y position, this code will calculate free-fall motion starting at 5 m with an initial upward velocity of 10 m/s. The calculation continues, upward and downward, until the position becomes 0 m and the it statement allows the break command to stop the code dead. Graphical Analysis In our study of kinematics, we have noted that a lot of useful information about motion can be gleaned from motion graphs such as stand ou... VPython has built in features that allow us to make graphs of any quantities we wish. The syntax is remarkably simple. In order to make graphs of position and velocity, we need to initiate the graphical curve routine for each, like this: gourve (color color.red e color color blue these lines need to be placed early in the code in order to initialize our graphs. Later in the code we begin to calculate positions and velocities in our while loop. All we need do is add: to the white loop. Each time the loop goes round, it will add the vertical position, vertical velocity and time to the graph. Ada these lines to the basic free-fall code provided and see what the result looks like. You should get a very pleasing graph that matches the physical motion that is being calculated Change the initial velocity and initial position to arbitrary but sensible values and run your code again. Paste your program A Big Task It's now time to use all of the techniques and skills that you have learned thus far to produce a final product more or less on your own. You will modify the basic code presented in the beginning of this lab to solve free-fall problems and create a pleasing animation to boot. Feel free to get creative with the way things look. VPython has lots of features that we haven't used yet, but are easily implemented and can make your code more fun/interesting/impressive. You can read about them here Begin with the base code and eliminate the graphs. Your code should accomplish the following tasks: Create a 3D object that will free-fall. Create a 3D box that will serve as the "ground" Prompt the user for the initial position, initial velocity and final position Add in any way) an indicator that the velocity of the object is positive or negative. (i.e. an arrow, a color, a label) Animate the motion until it reaches the final position. Output the final velocity. Output the total time Output the distance traveled. This is not a task that we have done before, so give it some thought. This may be the first time working with VPython that you get a lot of error messages. Don't get discouraged. There are a lot of little details to pay attention to and it is hard, if not impossible, to get it right on the first go. Remember to make your changes one at a time and run your code often to test your progress. Choose some reasonable initial conditions and solve the problem with pencil and paper. Once you know the answers, run the code to check. CHALLENGE: Modify your code so that the ball bounces instead of stopping. By the way, in your code does it look like the ball is going into the floor? I bet you can fix that. In your your OneDrive doc, paste an image of your pencil and paper solution Paste a screenshot of your final output into your OneDrive doc. Paste your final program into your OneDrive doc. Submit your OneDrive doc to the assignment on BBLeam

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

Students also viewed these Databases questions

Question

Define the goals of persuasive speaking

Answered: 1 week ago