Constructing a function based on a real-world scenario

A random thought came into my head today when I was in the subway:

Suppose we have a train in a subway where the stations are evenly spaced in a straight line. The train accelerates for some amount of time, moves with a constant speed for some amount of time, and starts decelerating until it reaches the next station such that the same amount of time spent accelerating and decelerating are the same, and the magnitudes of both are the same. Create a possible function that illustrates this scenario.

I decided that I would try to use some combination of a sinusoidal function and a linear function, since the train would try to do the same thing during certain periods of time, and the train is moving only in one direction. I hopped onto Desmos and played around a little bit, and I was able to create a function that gets me somewhat close to what I want. $$d_1(t)=t-\frac1{2\pi}\sin 2\pi t$$ I chose the constant multiple $$\frac1{2\pi}$$ to simplify the distance between each station to $$1$$, and the multiplier $$2\pi$$ for $$t$$ to suggest that it takes $$1$$ unit of time to get from one station to the next. Choosing the sinusoidal function means that there will be no length of time where the train is moving at a constant speed, and the acceleration and deceleration will be exactly opposite, separated by the point of inflection halfway between the stations.

The problem: trains usually stop at every station. I want to, arbitrarily at first, modify the function so that the train waits for the same amount of time as it takes to travel from one station to another. Eventually, I want to be able to construct a function that can describe the waiting time in some proportion to the traveling time. I came up with the function $$d_2(t)=\begin{cases}t-\frac{\lfloor t\rfloor}2-\frac1{2\pi}\sin 2\pi t,& \lfloor t\rfloor \textrm{ is even}\\ \frac{\lceil t\rceil}2,& \lfloor t\rfloor \textrm{ is odd} \end{cases}$$ This gets me something closer to what I want.

My questions:

1. What alternative ways of representing the scenario are there? For example, would it be possible to construct a piecewise function based only on polynomials that meets the criteria above?
2. Is there a way to represent this particular scenario without use of a piecewise function?
3. Suppose there must be a stretch of time where the train is moving at a constant speed between stations. How can I factor that in to the equation for the function?
4. Suppose the train makes the return trip in a similar manner, and it makes some number of return trips daily. Does this suggest that it can be written as a periodic function? If so, what would be the equation for that function?
• I know you tagged this as precalculus, but if you start by just considering the acceleration, you can then anti-differentiate to get velocity and anti-differentiate again to get distance. From the description you gave, you would end up with a piecewise function of quadratics. – 79037662 Oct 8 at 20:25
• Yes, I see where you are coming from, but I want to suppose that the acceleration may or may not be constant -- having the same sign is sufficient (e.g. having an acceleration $x>0$ in one interval, then having the deceleration (or negative acceleration) be the same magnitude, but different sign). Thanks for input; I will remove that tag since concavity of a function is based on knowledge of calculus. – Andrew Chin Oct 8 at 20:42
• You can try to make formal your conditions as differential equations, solving which will give you an infinite family of possible solutions. – YiFan Oct 8 at 20:52
• Particularly question 4, because of the periodicity aspect, made me think of Fourier Series: en.wikipedia.org/wiki/Fourier_series – Adam Rubinson Oct 8 at 21:40
• If you want your function to be constant in some sections, than it cannot be analytic. In your situation this translates to the fact that you need a piecewise definition. – quarague Oct 9 at 7:05

Just collecting various comments all in one place, and filling in some holes / details.

First, a function $$d(t)$$ is simply a mapping from values in the domain (in your case: time) to values in the range (in your case: distance). Whether you can write that function as a "nice" formula of "well-known" expressions, is kinda irrelevant. I should add though, the confusion between (abstract) functions and (nice) formulas is historic, so if you have the same confusion, you're not alone. :)

In the context of $$d(t)$$ being the motion of a train, there are reasonable assumptions to be adopted, e.g. $$d$$ should be continuous (the train does not "teleport"), differentiable (velocity is well defined) and maybe twice differentiable (acceleration is well defined). However, even after adopting these, there is nothing special about sinusoids. (In the context of a moving pendulum, or (idealized) planetary rotation, maybe sinusoids would be natural, but a moving train...?)

Q1: As answered by @79037662 it is surely possible to model the train motion $$d(t)$$ as piecewise polynomial - and in fact for a train this would probably be more natural than modeling by sinusoids. Assuming no friction (ha!) a zero acceleration would give constant velocity $$v(t)$$ and linear $$d(t)$$, a constant non-zero acceleration would give linear velocity $$v(t)$$ and quadratic $$d(t)$$, a linear acceleration would give quadratic $$v(t)$$ and cubic $$d(t)$$, etc. If you have pieces of acceleration you will have pieces of polynomial $$d(t)$$ and once you have pieces of polynomials you simply have to be careful to "glue" them together. The piecewise formula might be tedious to write out but there is nothing magical going on.

Q2: As answered by @quarague it is not possible for your function to have a constant stretch and also be analytic, and "analytic" very roughly translates to something with a nice formula (and probably includes most "familiar" functions you have in mind: polynomials, sinusoids, exponentials, etc). This is actually a non-trivial result. This applies to both distance (constant distance implying stopping at a station) and velocity: If you have constant stretches and non-constant stretches (in either distance or velocity), then you will have to write your function as piecewise.

Q3: Constant speed simply means that part of $$d(t)$$ is linear, e.g. $$d(t) = v t + C$$. Here $$v$$ is the constant velocity. You get this $$d(t)$$ by integrating $$v$$ over $$t$$.

Q4: As answered by @AdamRubinson Fourier Series would be a way to go, but for the purpose of writing out the function it's probably overkill. Suppose $$d^*(t)$$ for $$t \in [0,1]$$ describes what happens to the train in the first hour, and $$d^*(0)=d^*(1)$$ s.t. the train makes a complete round trip. Further suppose the train does this every hour, then you can simply write the overall $$d(t)$$ as

$$d(t) = d^*(t - \lfloor t \rfloor)$$

Here $$\lfloor t \rfloor$$ is the standard notation for the "floor" function which denotes the greatest integer $$\le t$$, so e.g. if $$t=13.7$$ then $$\lfloor t \rfloor = 13$$ and $$t - \lfloor t \rfloor = 0.7$$ gives the fraction part of $$t$$. Note that while "floor" is a "standard" function, it is piecewise. Which in a roundabout way brings us back to the your Q2: you can always describe a piecewise function in a non-piecewise way... if you define a new name for it! :)

Hope this helps (as opposed to confuses even further!)

• Thanks for a detailed response! Got a final question for you: suppose I wanted to create a polynomial function for my above $d_1(t)$ on, say, $[0,m]$. Is there a way to ensure that the "bumps" that I have are all uniform (like, $(n,n+1)$ acts the same as $(n-1,n)$ except one unit up)? It is (in addition to my naivety or my lack of training) why I tried to think about it using a periodic function in the first place. – Andrew Chin Oct 9 at 16:12
• Say $x$ is a variable $\in (0,1)$, then you seem to be saying you want $f(n+x) = f(n-1 + x) + 1$. The only polynomial function that does that would be linear; quadratics, cubics etc all never do that. So if $f$ is polynomial but not linear, then you have to specify $f$ as piecewise polynomial, e.g. maybe use my idea in Q4 or something similar. – antkam Oct 9 at 17:18