The average speed for the whole trip is the total distance traveled divided by the total time it took to travel that distance.
Distance = Rate * Time
The distance in both cases is the same, the rates are different and the times are different.
Call the time for A to B t and the time for B to A T
For A to B distance = 40t and for B to A the distance = 60T
The average speed for the trip is then (40t+60T)/(T+t)
Since the distances are the same we know 40t=60T and thus t = 60/40 * T = (3/2)T.
So the average speed is (40*(3/2)T + 60T)/(T+(3/2)T = 120T/(5/2)T = 120*2/5 = 48 MPH
If you need help understanding math so you can solve these problems yourself, then one on one online tutoring is the answer ($30/hr). If you need faster solutions with guaranteed detailed answers, then go with personal problem solving ($3.50-$5.50 per problem). Contact me at fcabanski@hotmail.com