I don’t want to cause a big sensation – but something got better!
One of rail’s advantages over other transport modes was being able to take the energy of motion, convert it to electricity and send it back where it came from for a full refund. I say ‘was’, because now it is what makes electric cars viable.
The physics is pretty basic, if you run an electric current through a wire in a magnetic field it will move, reverse the current and it moves again, and so the motor rotates. Current reversal can be mechanical or electronic, we don’t need to worry about the detail. If you apply force to the wire to move it in a magnetic field, that will generate electricity, move it back again… and so on. A motor is a generator, depending on how you use it.
Motors even generate power when you don’t want them to, so to get over that you need to reduce the magnetic field as they speed up, generating a voltage against what you are putting in. Hence the locos I grew up with have ‘field diverts’ to weaken the magnetic field and so reduce generation. Modern AC motors are smaller for a given power and need clever electronics to control the current, but now electronic control is relatively cheap and reliable nearly all traction has AC motors.