A mathematical model of the longitudinal flexibility of a continuously welded railway track and the methodology for the analysis of the longitudinal displacement of rails under the effects of passing trains is developed to investigate the longitudinal behavior of rails. The purpose of this analysis is to explore the changes of longitudinal stress distribution in the rails due to mechanical loading applied by a travelling train. A half track system is used to derive the equations required to obtain the magnitude of deflection and force of rails and these values are scaled to produce the displacement pattern using the method of superposition. The mathematical model is translated into MATLAB and validation of the program is verified through comparisons of displacement patterns generated by a computer software LONGIN. Analysis of a straight track due to train braking was performed over a track length of 1000 m. The longitudinal displacement obtained showed that maximum longitudinal displacement occur in the middle of the track at the distance of 570 m which is in direct agreement with the published result.