Lagrangian method for difference equation