Simulating Free Fall Using Euler's Method in C

In summary, the program calculates the time it takes for the object to fall to the ground, and the impact velocity.
  • #1
njo
20
0

Homework Statement


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 Euler’s method to numerically solve the differential equations describing the motion of a falling object. In Euler’s 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.

I'm having difficulty understanding what to do here. I don't really understand what the point of using these equations when t=sqrt(2d/g) gives us time of free fall.

Thanks for the help.

Homework Equations


v(t+dt) = v(t) + g * dt
p(t+dt) = p(t) + v(t+dt) * dt
p(t+dt) = p(t) - v(t+dt) * dt

The Attempt at a Solution



p(t+dt) = p(t) - v(t+dt) * dt
 
Physics news on Phys.org
  • #2
njo said:

Homework Statement


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 Euler’s method to numerically solve the differential equations describing the motion of a falling object. In Euler’s 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.

I'm having difficulty understanding what to do here. I don't really understand what the point of using these equations when t=sqrt(2d/g) gives us time of free fall.

Thanks for the help.

Homework Equations


v(t+dt) = v(t) + g * dt
p(t+dt) = p(t) + v(t+dt) * dt
p(t+dt) = p(t) - v(t+dt) * dt

The Attempt at a Solution



p(t+dt) = p(t) - v(t+dt) * dt
Welcome to the PF.

Yes, clearly without any air resistance issues, you can solve for this algebraically. But the point of the programming exercise is to give you an easy problem to solve numerically. You should compare the answers you get from your numerical solution with the equation you mention, to see what the accuracy is. You could even vary the dt values to see how they affect the accuracy of the numerical solution. :smile:
 
  • #3
njo said:
I'm having difficulty understanding what to do here. I don't really understand what the point of using these equations when t=sqrt(2d/g) gives us time of free fall.

I give a similar exercise to my students. The point is to give you some practice with numerical integration. The fact that you know the analytic solution allows you to check your answer. The importance of the exercise is that for many (most?) 'real' problems (systems modeled by differential equations) an analytic solution may not exist, or may be very difficult to find. Numerical integration allows for a relatively easy way to analyze the system.

Edit: Sorry for the redundancy - berkeman's post must have posted as soon as I started typing!
 
  • Like
Likes berkeman
  • #4
I'm still unsure what v(t+dt) and p(t+dt) represent.
 
  • #5
njo said:
I'm still unsure what v(t+dt) and p(t+dt) represent.
It's probably best to start with an Excel spreadsheet to get a feel for how these sequential calculations go.

The first column is time, starting at zero, and incrementing by dt for each row after that. The second column is y(t), the third is velocity v(t). All are zero in the first row.

Then put in formulas into the second row, second and third columns to calculate the new position and velocity based on the previous values in the previous row. That's what v(t+dt) and p(t+dt) represent. Then just do a click-drag down for the y(t) and v(t) cells and do a Fill-Down to paste the same formulas (with adjusted row numbers) in the cells below. You should see how the position and velocity are changing with time when you do this. Makes sense?

Then you just need to code up the same thing in C... :smile:
 
  • Like
Likes brainpushups
  • #6
v(t+dt) is the velocity after a short time interval. Even for non-constant acceleration the velocity will be approximately linear for very short intervals of time - that's why the method is so simple.

p(t+dt) is the position after a short time interval. Similar to the example above the change in position is approximately linear for short time intervals. You use the velocity you calculated to calculate each subsequent change in position.

As @berkeman said, it would be worth your time to set this up in a spreadsheet - that is actually what I instruct my students to do.
 
  • #7
How would I solve for time with these equations though? if g=-32.2 and assume p=100?
 
  • #8
You don't solve for time in the algebraic sense - you iterate the equations until the desired position is reached. Time is a parameter that everything else depends on and you pick the time step, dt. For example, suppose we pick a time step of 1 second (a poor choice if we want to be close to approximate for the position). The first few columns for various rows in a spreadsheet would look like:

t a v p
0 10 0 0
1 10 10 0
2 10 20 10
3 10 30 30
4 10 40 60
5 10 50 100

Edit: hopefully you can understand what I've written here; I just quickly typed it in nicely spaced so I didn't need to spend time making a chart, but the spacing didn't show up right... (a is acceleration, v is velocity, p is position and I used an acceleration of 10 to make the numbers look nice.)

The nth entry in the velocity column is calculated by using the n-1 acceleration term and adding the n-1 velocity. Similarly, the nth position entry is calculated by using the n-1 velocity and adding the n-1 position.

Suppose the question is to find the time for the object to fall 100 meters. The time would be 5 seconds according to this spreadsheet. Does that help?
 
  • Like
Likes berkeman
  • #9
It's making a bit more sense. What is your work to calculate those values? If we assume dt=1 and g=10 and p=10, does that mean p(0)=100?

p(t+1) = p(t) + v(t) + 10 is this true?

I really appreciate the help
 
  • #10
Let me start with the velocity explicitly. Let v0 be the initial velocity. The next velocity (after time dt) will be

v1 = a0 * dt + v0 where a0 is the initial acceleration (note that for free fall the acceleration is always constant, but I'm going to give instructions as if it was changing so everything is more general, and hopefully more clear).

Then, the velocity after the second time interval is

v2 = a1 * dt + v1

And the third velocity is

v3 = a2 * dt + v2

And so on. In the line for t = 4 seconds in post 8 above the velocity was calculated as v4 = (10) (1) + 30 = 40

The position works the same way except you use the velocity in place of the acceleration:

p1 = v0 * dt + p0

p2 = v1 * dt +p1

p3 = v2 *dt +p2

So p4 from the example in post 8 is p4 = 30 * 1 + 30 = 60

And p5 is p5 = 40 * 1 + 60 = 100
 
  • Like
Likes berkeman
  • #11
Alright it makes sense now. Thanks so much for the help.
 

1. What is Euler's Method and how is it used in physics?

Euler's Method is a numerical method used to approximate the solutions of ordinary differential equations. In physics, it is commonly used to solve problems related to motion and free fall, where the equations of motion are difficult to solve analytically.

2. How does Euler's Method work?

Euler's Method works by breaking down a continuous function into small intervals and using linear approximations to estimate the value of the function at each interval. These approximations are then used to calculate the next value of the function, and the process is repeated until the desired solution is obtained.

3. What are the limitations of using Euler's Method in free fall problems?

Euler's Method is not always accurate, as the linear approximations used can introduce errors. In free fall problems, these errors can accumulate over time, leading to significant deviations from the actual solution. Additionally, Euler's Method assumes a constant acceleration, which may not always be the case in real-life scenarios.

4. How does free fall relate to Euler's Method?

In physics, free fall refers to the motion of an object falling under the influence of gravity without any other forces acting on it. Euler's Method can be used to solve equations of motion in free fall, such as finding the position, velocity, and acceleration of an object at different points in time.

5. Can Euler's Method be used to solve any type of differential equation?

No, Euler's Method is only applicable to first-order ordinary differential equations. It cannot be used to solve partial differential equations or higher-order differential equations. Additionally, it may not be suitable for equations with complex or discontinuous solutions.

Similar threads

  • Calculus and Beyond Homework Help
Replies
3
Views
574
Replies
3
Views
1K
  • Calculus and Beyond Homework Help
Replies
1
Views
991
  • Calculus and Beyond Homework Help
Replies
32
Views
2K
Replies
10
Views
693
  • Calculus and Beyond Homework Help
Replies
1
Views
1K
  • Calculus and Beyond Homework Help
Replies
5
Views
3K
  • Calculus and Beyond Homework Help
Replies
1
Views
675
  • Calculus and Beyond Homework Help
Replies
9
Views
1K
  • Classical Physics
Replies
0
Views
149
Back
Top