Post Reply 
The Two Train Problem
02-23-2018, 05:09 AM
Post: #1
The Two Train Problem
Blog Entry: https://edspi31415.blogspot.com/2018/02/...train.html

Have you ever heard the infamous problem “two trains are heading towards each other…”?

Today’s blog will cover the following question:

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?

[Image: Two%2Btrain%2Bdiagram.jpg]


According to the diagram above, we have two trains, labeled Train I and Train II, each going at velocity v and acceleration a. The trains start at distance D apart. We will call the point where the trains cross over the same spot, x.

Notes:

1. To make our lives easier, let’s assume that Train I starts at position 0, while Train II starts at position D.

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.

We are going to cover two scenarios: one where there is no acceleration, that is the velocity of both trains is constant. The other is where acceleration is present for at least one of the trains.

In general the distance equations for both trains are:

Train I: x = v1*t + a1*t^2
Train II: x = D - v2*t - a2*t^2

What this boils down to are a system of two equations, solving for both t and x.

The Program TRAINS

The program TRAINS will solve this problem. Below are the codes for both the HP Prime and Casio fx-5800p. Enter each as a positive value as the directions are accounted for in the program.

In the program, Train I is considered the left train, while Train II is considered the right train.

HP Prime Program: TRAINS
Code:

EXPORT TRAINS()
BEGIN
// 2018-02-22 EWS
// 2 trains problem

LOCAL d,t,x;
LOCAL v1,a1,v2,a2;

INPUT({d,v1,a1,v2,a2},
"Two Opposing Trains",
{"Dist:","L Vel:","L Acc:",
"R Vel:","R Acc:"},
{"Distance between trains",
"Left Train: Velocity",
"Left Train: Acceleration",
"Right Train: Velocity",
"Right Train: Acceleration"});

// calculation
IF a1≠0 OR a2≠0 THEN
t:=(−(v1+v2)+√((v1+v2)^2+
4*d*(a1+a2)))/(2*(a1+a2));
x:=v1*t+a1*t^2;
ELSE
t:=d/(v1+v2);
x:=v1*t;
END;

// results
RETURN {"Time",t,
"Position",x};


END;
Visit this user's website 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)