Rocket Launch Simulation
Design a program that lets you simulate the flight of a rocket, considering the effects of gravity, drag, and thrust forces. The program should use nested loops to update the rocket's position, velocity, and acceleration while incorporating user-provided initial parameters. It should also use conditionals to check if the rocket has reached the target altitude or crashed. The program read the initial position, velocity, mass of the rocket, the target altitude, and the thrust force. After the simulation, the program should display the rocket's trajectory and final status.
You may calculate the update on acceleration using the following formula:
acceleration = (thrust_force - mass * gravity - drag) / mass
You may assume the drag value to be 10% of the current velocity and the acceleration value due to gravity to be 9.81 m/s^2.
Do not round off any value during calculation. All outputs must be done with the resolution of one decimal place only (use fstrings to impose this restriction).
Input Format:
The program should expect the following five inputs, each on a separate line:
- Initial altitude in meters (a floating-point number).
- Initial velocity in meters per second (a floating-point number).
- Mass of the rocket in kilograms (a floating-point number).
- Target altitude in meters (a floating-point number).
- Thrust force in Newtons (a floating-point number).
Output Format:
The program provides the following information in the output:
- Comma-separated values on each line, representing time (in seconds), altitude (in meters), and velocity (in meters per second) at regular intervals.
- The final status of the rocket as one of the following: "Rocket reached the target altitude.", "Rocket crashed.", or "Simulation ended without reaching the target altitude."
Sample Input:
0.0
0.0
100.0
1000.0
5000.0
Sample Output:
0.0, 0.0, 0.0
1.0, 40.2, 40.2
2.0, 120.5, 80.3
3.0, 241.0, 120.4
4.0, 401.5, 160.5
5.0, 602.0, 200.5
6.0, 842.6, 240.5
7.0, 1123.1, 280.5
Rocket reached the target altitude.
Comments