The paper formulated the variational principle for a class of boundary value problems described by ordinary differential equations of the second order. The variational principle was used to obtain approximate solutions by the Ritz procedure. The procedure for evaluating the error of the approximate solutions obtained in this way is given. For a specific example of buckling, with the participation of geometric nonlinearity, an approximate solution was determined and its error was evaluated.