We propose a nonlinear lagrangian model that takes into account the dynamic interactions between the soil and a n-storey plane frame, which may be subjected to a seismic excitation through the soil. First, the interaction of the soil with the structure is modeled through a combination of springs and dampers representing the characteristics of the soil. In this model, the masses and stiffnesses of the structure elements are condensed to facilitate the analysis. Second, the Euler-Lagrange equations of the system are formulated and generalized for n floors. Third, these equations are discretized using the finite difference method to solve them using the Newton-Raphson method at each time step, during and after the seismic excitation, thus, determining the positions of each concentrated mass of the system. In addition, a linearization of the governing equations is performed in order to compare these results with those of the nonlinear model. Finally, the nonlinear model is used for the analysis of a 10-storey building, which has already been designed for linear geometric and material behaviors. For this analysis, the corrected acceleration record of the 2016 Pedernales (Ecuador) earthquake is used.