Question
Write a C program to simulate a falling object. The program should ask for the initial height of the object, in feet. The output of
Write a C program to simulate a falling object. The program should ask for the initial height of the object, in feet. The output of the program should be the time for the object to fall to the ground, and the impact velocity, in ft/s and miles/hour. Your program should use Eulers method to numerically solve the differential equations describing the motion of a falling object. In Eulers method, the state of the object at some small future time is calculated using the values at the present time. This small future timestep is typically called delta time, or dt. Thus the position (p) and speed (v) of the object in the next timestep t + dt is written as a simple function of the position and speed at the current timestep t (g is the acceleration due to gravity):
v(t+dt) = v(t) + g * dt
p(t+dt) = p(t) + v(t+dt) * dt
You should actually start out with the velocity as zero, and the position at the initial height of the object. Then your position (above the ground) would be:
p(t+dt) = p(t) - v(t+dt) * dt
And you would integrate until the position becomes less than or equal to zero.
The input/output formats for your program should look like this: Program to calculate fall time and impact speed of a falling object dropped from a specific height.
Enter initial height in feet: 100 Falling time = 2.492224 seconds Impact speed = 80.249613 feet/sec Impact speed = 54.715645 mph
CODE: I need to use a while or for loop, either one is okay...
#include
//function main begins program excution
int main(void) { float T;// falling time float dt = 0.49845; // the future timestep in seconds float G = 32.2; // universal gravitational ocnstant in feet per second per second float v0 = 0.0; //initial velocity float v1, v2, v3, v4, v5, v6; // velocity of the falling object after dt printf("program to calculate fall time and impact speed of a falling object dropped from a specific height. ");// define this program float p0; //initial height to be entered by user printf("Enter initial height in feet: "); //prompt scanf("%f", &p0); // read initial height float p1, p2, p3, p4, p5, p6, p7; // position of the falling object after time dt
v1 = G*dt+v0; // velocity of the falling object at time dt v2 = G*dt+v1; // next velocity of the falling object after time dt v3 = G*dt+v2; // next velocity of the falling object after time dt v4 = G*dt+v3; // next velocity of the falling object after time dt v5 = G*dt+v4; // next velocity of the falling object after time dt v6 = G*dt+v5; // next velocity of the falling object after time dt
p1 =v0*dt+p0; // position of the falling object at time dt p2 =v0*dt+p1; // next position of the falling object at time dt p3 =v0*dt+p2; // next position of the falling object at time dt p4 =v0*dt+p3; // next position of the falling object at time dt p5 =v0*dt+p4; // next position of the falling object at time dt p6 =v0*dt+p5; // next position of the falling object at time dt p7 =v0*dt+p6; // next position of the falling object at time dt
T = 5*dt;// falling time printf("falling time =%.6f seconds ", T); // display falling time
printf("impact speed = %.6f feet/sec ", v5); // display impact speed in feet/sec
//Convert velocity from feet/sec to mile/hour multiply by 0.682
v5 = v5*0.682; // Impact speed in mile/hour
printf("Impact speed = %.6f mph ", v5); // display impact speed in mile/hour }
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