Java Reference
In-Depth Information
The velocity changes constantlyȌin fact, 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. Get
the initial velocity as an input (100Юm/sec is a good value). Update the
position and velocity 100 times per second, but only print out the
position every full second. Also print out the values from the exact
formula s(t) = ɨ0.5 – g – t 2 + v 0 – t for comparison. Use a class
Cannonball .
What is the benefit of this kind of simulation when an exact formula is
available? Well, the formula from the calculus book is not exact.
Actually, the gravitational force diminishes the farther the cannonball is
away from the surface of the earth. This complicates the algebra
sufficiently that it is not possible to give an exact formula for the actual
motion, but the computer simulation can simply be extended to apply a
variable gravitational force. For cannonballs, the calculus-book formula
is actually good enough, but computers are necessary to compute
accurate trajectories for higher-flying objects such as ballistic missiles.
΢΢ Exercise P6.3. Write a program that prints the powers of ten
1.0
10.0
100.0
1000.0
10000.0
100000.0
1.0E7
1.0E8
1.0E9
1.0E10
1.0E11
Implement a class
Search WWH ::




Custom Search