In this paper, considering all the linear and nonlinear inertia terms of moving masses on a flexible beam, the dynamic response and dynamic stability of the beam are studied. Homotopy perturbation method is used to perform the analysis and results are provided in a stability map for the different values of mass and velocity of the moving masses. It is concluded that there is a borderline in the diagram that separates the stable and unstable regions. For the first time, this borderline is determined semi-analytically. Results of the stability analysis are validated using the Floquet theory. In addition to this borderline, it is also concluded that the Homotopy perturbation method is capable of evaluating the new critical values for mass and velocity which cause vibration resonance in the beam. The locus of these resonant points, which is totally a new finding in dynamic analysis of beam-moving mass problem, is determined semi-analytically. Finally, the effect of the friction between the beam and the moving mass is studied on the stability of the system and resonant conditions. Accuracy of the results for this case is also evaluated with a numerical simulation.