Distance travelled by the first train in 2 hours
= OA = Speed x Time
= 2 (x + 5) km
Distance travelled by the second train in 2 hours
= OB = Speed x Time
= 2x km
By using pythagoras theorem, we have,
AB2 = OA2 + OB2
⇒ 502 = {2(x + 5)}2+ {2x}2
⇒ 2500 = 4(x + 5)2 + 4x2
⇒ 8x2 + 40x – 2400 = 0
⇒ x2 + 5x – 300 = 0
⇒ x2 + 20x – 15x – 300 = 0
⇒ x (x + 20) – 15 (x + 20) = 0
⇒ (x + 20) (x – 15) = 0
⇒ x = –20 or x = 15
⇒ x = 15
[∵ cannot be negative]
Hence, the speed of the second train is 15 km/hr and the speed of the first train is 20 km/hr.