Post Reply 
The Two Train Problem
02-26-2018, 10:59 AM (This post was last modified: 02-28-2018 08:22 PM by Dieter.)
Post: #5
RE: The Two Train Problem
(02-23-2018 05:09 AM)Eddie W. Shore Wrote:  Two trains are heading towards each other, on their own separate train track. Each train has going at their own speed (velocity). The trains start out a distance apart.

1. When will the trains cross over the same spot, and

2. Where will the trains cross over the same spot?

...

2. Train I is going at velocity v and acceleration a.

3. Train II is going at velocity –v and acceleration –a. Why negative? Train II is traveling in the opposite direction of Train I.

Setting up the Equations

The general distance equation is: x = x0 + v*t + a*t^2, where x0 is the initial position.

Here actually v is v0, the initial train speed. This means you assume that the trains are on their track, running at a speed of "v" and then they accelerate to even higher speeds from there. BTW the acceleration "a" can also be negative, in this case the train is slowing down.

Let me add a variation that is closer to real life: Let's assume both trains start at their respective stations, i.e. they initially have a speed of v0=0. Then each train is accelerating with a rate of "a" until it has reached its final velocity "v". From that point on it is running at a constant speed "v".

The acceleration phase happens for t ≤ v/a := T
For t > T the train runs at constant speed v.

So with T = v/a the train's position x can be given as follows:

t ≤ T:  x = 1/2 a t²
t > T:  x = 1/2 a T² + v·(t–T)

This can also be written as

x = 1/2 · a · min(t, T)^2 + v · (max(t, T)-T)
or
x = 1/2 · a · min(t, T)^2 + v · max(t–T, 0)

where T = v/a.

You can also do this for the second train where the position is D – x.

For the example data in your blog this yields a solution of

t =   13,093
x = 128,571

Check:

For the first 40/1,5 = 26,667 seconds train I is accelerating. Since 13,093 falls within this interval the train has reached a position of x = 1/2 · 1,5 · 13,093² = 128,57.

The second train accelerates during the first 35/2 = 17,5 seconds. 13,093 is also less than this, so train II is still accelerating as well. It has travelled a distance of 1/2 · 2 · 13,093² = 171,43 from its starting point D, which again is 300 – 171,43 = 128,57 relative to the starting point of train I.

Since both trains are still accelerating the calculation is easy here:

1/2 a1 t² = D – 1/2 a2 t²
t = √ [ 2D / (a1+a2) ]

For the example with D=300, a1=1,5 and a2=2 this yields t = 13,093.

A program that calculates a solution for this scenario has to handle three cases:

1. Both trains are accelerating
2. One of the train is accelerating while the other one runs at constant speed.
3. Both trains are running at constant speed

What about such a program?

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
The Two Train Problem - Eddie W. Shore - 02-23-2018, 05:09 AM
RE: The Two Train Problem - PedroLeiva - 02-25-2018, 02:04 PM
RE: The Two Train Problem - Dieter - 02-25-2018, 06:19 PM
RE: The Two Train Problem - PedroLeiva - 02-25-2018, 10:55 PM
RE: The Two Train Problem - Dieter - 02-26-2018 10:59 AM
RE: The Two Train Problem - Eddie W. Shore - 02-28-2018, 10:27 PM
RE: The Two Train Problem - Eddie W. Shore - 03-01-2018, 02:35 AM
RE: The Two Train Problem - Eddie W. Shore - 03-01-2018, 02:54 AM
RE: The Two Train Problem - Dieter - 03-01-2018, 08:53 AM
RE: The Two Train Problem - Eddie W. Shore - 03-01-2018, 01:03 PM
RE: The Two Train Problem - chromos - 03-01-2018, 02:00 PM



User(s) browsing this thread: 1 Guest(s)