speed = distance / time

Therefore,

time = distance/speed

Let's assign some symbols to these quantities...

time = t

speed = v (from 'velocity')

distance = s (don't ask... people just like using s for distance. it crops up a lot in maths too for path lengths and things like that)

The equation above described in symbols is:

\(\displaystyle t = \frac{s}{v}\)

Let's use the numbers 1, 2 and 3 to designate the three parts of a journey. These are called "indices".

Time for first part of journey:

\(\displaystyle t_1 = \frac{s_1}{v_1}\)

Time for second part of journey:

\(\displaystyle t_2 = \frac{s_2}{v_2}\)

Time for third part of journey:

\(\displaystyle t_3 = \frac{s_3}{v_3}\)

Total time for journey:

\(\displaystyle t_{total} = t_1 + t_2 + t_3\)

Substitute for individual times, we get:

\(\displaystyle t_{total} = \frac{s_1}{v_1} + \frac{s_2}{v_2} + \frac{s_3}{v_3}\)

The total distance is:

\(\displaystyle s_{total} = s_1 + s_2 + s_3\)

Therefore, the average speed is:

\(\displaystyle \bar{v} = \frac{s_{total}}{t_{total}} = \frac{s_1 + s_2 + s_3}{\frac{s_1}{v_1} + \frac{s_2}{v_2} + \frac{s_3}{v_3}}\)