3.6 KiB
3.6 KiB
Question 04:
Simulating the Motion of a Particle in a Gravitational Field
Scenario:
Imagine a particle is released from a certain height above the ground and is subject to gravitational acceleration. The particle falls freely under gravity until it hits the ground. For simplicity, assume that air resistance is negligible, and the only force acting on the particle is gravity.
Problem Statement:
You are required to write a program that simulates the motion of the particle.
- Initialize the height from which the particle is released.
- Use a loop to update the position of the particle at each time step.
- Use an if-else statement to check if the particle has hit the ground.
- Print the height of the particle at each time step until it hits the ground.
Assumptions:
- Gravitational acceleration (g) is 9.8 m/s².
- The time step (Δt) for the simulation is 0.1 seconds and t is the current time.
- The initial height (h) from which the particle is released is 100 meters.
- Assume velocity and mass are ZERO (for ease of programming)
Instructions (for reference):
- Initialize the height of the particle to 100 meters.
- Use a while loop to simulate the motion of the particle until it hits the ground.
- Inside the while loop, use an if-else statement to check if the particle has hit the ground.
- Update the height of the particle using the equation of motion: h = hinitial − 1/2 _ g _ (t)2.
- Print the height of the particle at each time step.
- Use a for loop to iterate through the time steps.
Deliverables:
- A well-commented code that simulates the motion of the particle.
- A brief explanation of how the code works.
Sample Output 1:
Enter the time step in seconds: 0.1
Enter the height in meters: 1
Time: 0.0 s, Height: 1.00 m
Time: 0.1 s, Height: 0.95 m
Time: 0.2 s, Height: 0.80 m
Time: 0.3 s, Height: 0.56 m
Time: 0.4 s, Height: 0.22 m
Time: 0.5 s, Height: 0.00 m
The particle has hit the ground.
Sample Output 2:
Enter the time step in seconds: 0.2
Enter the height in meters: 2
Time: 0.0 s, Height: 2.00 m
Time: 0.2 s, Height: 1.80 m
Time: 0.4 s, Height: 1.22 m
Time: 0.6 s, Height: 0.24 m
Time: 0.8 s, Height: 0.00 m
The particle has hit the ground.
Sample Output 3:
Enter the time step in seconds: 0.1
Enter the height in meters: 100
Time: 0.0 s, Height: 100.0 m
Time: 0.1 s, Height: 99.95 m
Time: 0.2 s, Height: 99.80 m
Time: 0.3 s, Height: 99.56 m
Time: 0.4 s, Height: 99.22 m
Time: 0.5 s, Height: 98.78 m
Time: 0.6 s, Height: 98.24 m
Time: 0.7 s, Height: 97.60 m
Time: 0.8 s, Height: 96.86 m
Time: 0.9 s, Height: 96.03 m
Time: 1.0 s, Height: 95.10 m
Time: 1.1 s, Height: 94.07 m
Time: 1.2 s, Height: 92.94 m
Time: 1.3 s, Height: 91.72 m
Time: 1.4 s, Height: 90.40 m
Time: 1.5 s, Height: 88.97 m
Time: 1.6 s, Height: 87.46 m
Time: 1.7 s, Height: 85.84 m
Time: 1.8 s, Height: 84.12 m
Time: 1.9 s, Height: 82.31 m
Time: 2.0 s, Height: 80.40 m
Time: 2.1 s, Height: 78.39 m
Time: 2.2 s, Height: 76.28 m
Time: 2.3 s, Height: 74.08 m
Time: 2.4 s, Height: 71.78 m
Time: 2.5 s, Height: 69.37 m
Time: 2.6 s, Height: 66.88 m
Time: 2.7 s, Height: 64.28 m
Time: 2.8 s, Height: 61.58 m
Time: 2.9 s, Height: 58.79 m
Time: 3.0 s, Height: 55.90 m
Time: 3.1 s, Height: 52.91 m
Time: 3.2 s, Height: 49.82 m
Time: 3.3 s, Height: 46.64 m
Time: 3.4 s, Height: 43.36 m
Time: 3.5 s, Height: 39.97 m
Time: 3.6 s, Height: 36.50 m
Time: 3.7 s, Height: 32.92 m
Time: 3.8 s, Height: 29.24 m
Time: 3.9 s, Height: 25.47 m
Time: 4.0 s, Height: 21.60 m
Time: 4.1 s, Height: 17.63 m
Time: 4.2 s, Height: 13.56 m
Time: 4.3 s, Height: 9.40 m
Time: 4.4 s, Height: 5.14 m
Time: 4.5 s, Height: 0.77 m
Time: 4.6 s, Height: 0.00 m
The particle has hit the ground.