Question
C++ Simulation Suppose a cannonball is propelled vertically into the air with a starting velocity of v0. A physics textbook would give the position of
C++ Simulation
Suppose a cannonball is propelled vertically into the air with a starting velocity of v0. A physics textbook would give the position of the ball after t seconds as: (1) s(t) = 0.5 g t^2 + v0 t where g is the gravitational force of the earth, and g = 9.81 m/sec2 . We will confirm equation 1 by a simulation. In our simulation, we will consider how the ball moves in very short time intervals t. In a short time interval, the velocity v is nearly constant, and we can compute the distance the ball moves as s = v t. In our program, we can set a variable double deltaT = 0.01; and update the position by s = s + v * deltaT; The velocity changes constantly: it is reduced by the gravitational force of the earth. In a short time interval, v decreases by g t, and we must keep the velocity updated as v = v - g * deltaT; In the next iteration the new velocity is used to update the distance. Now run the simulation until the cannonball falls back to the earth. Set the initial velocity to either 100 m/s, or to a randomly chosen value between 50 m/s and 150 m/s. Update the position and velocity 100 times per second, but only print out the experimental position every full second, along with the value from the exact formula (equation 1), for comparison. At the end, print the final time t when the ball hits the ground.
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