# Calculate distance travelled with non-constant speed after time t

Let's Imagine such a situation.
A man is walking for the first hour with a speed of $$4km/h$$.
The next hour he is jogging, with the speed of $$9km/h$$
Finally, after two hours, he starts to run, with the speed of $$12km/h$$

As one might expect, I want to calculate the distance which has been travelled after given time in hours $$t$$.

My approach to solve such a problem was to first determine, how long has the runner been going.
If it was less than one hour, his distance would be $$t*V_{0}$$.
If it was more than one hour, but less than two, it would be $$V_{o}+(t-1)V_{1}$$
Finally, if he has been going for more than two hours: $$V_{0}+V_{1}+(t-2)V_{2}$$

This way of doing calculations is valid and works, but I am looking for a better way which I guess must exist.
Is there any way to describe distance with a function of variable $$(t)$$ which is described by a single formula(Instead of three like right now)?

If it is not possible, can this be proven mathematically?

## migrated from physics.stackexchange.comSep 23 '18 at 20:08

This question came from our site for active researchers, academics and students of physics.

• This is an example of piecewise function, nothing wrong with it: en.wikipedia.org/wiki/Piecewise – Stéphane Rollandin Sep 22 '18 at 9:29
• Sure It is usable and calculations are valid, but It is hard to compare such functions. Say I have two runners, both have their distances defined by a picewise function. One of the runners starts later than the first one, but generally his average speed is higher. To calculate time after they will meet I have to consider many cases, that's why I'm looking for a faster way – Karol Szustakowski Sep 22 '18 at 11:06
• What you are asking about is mathematics not physics. – sammy gerbil Sep 22 '18 at 11:14
• Your speed vs time graph has 2 points where the angle changes abruptly (3 points if we include the starting point). No finite polynomial function can do that. And of course that's not physically realistic either, since it requires infinite acceleration at those points. You can paste your 3 line segments together using special functions like min & max, where min(a, b) is the minimum of a & b, but that doesn't really help much. – PM 2Ring Sep 22 '18 at 13:03
• why would you believe there is a single (not piecewise) function for the distance when your velocity is a piecewise function? – ZeroTheHero Sep 22 '18 at 13:19

You can use the Heaviside function. The answer would look like $$d(t)=t[V_0H(t)+(V_1-V_0)H(t-1)+(V_2-V_1-V_0)H(t-2)]$$
• No problem. The usefulness of this solution comes from the fact that in real life (physics) you might approximate the step function with something like $erf$, or $\tanh$ – Andrei Sep 27 '18 at 19:00