The paper deals with the problem of finding the field of force that generates a given ($N-1$)-parametric family of orbits for a mechanical system with $N$ degrees of freedom. This problem is usually referred to as the inverse problem of dynamics. We study this problem in relation to the problems of celestial mechanics. We state and solve a generalization of the Dainelli and Joukovski problem and propose a new approach to solve the inverse Suslov's problem. We apply the obtained results to generalize the theorem enunciated by Joukovski in 1890, solve the inverse Stäckel problem and solve the problem of constructing the potential-energy function $U$ that is capable of generating a bi-parametric family of orbits for a particle in space. We determine the equations for the sought-for function $U$ and show that on the basis of these equations we can define a system of two linear partial differential equations with respect to $U$ which contains as a particular case the Szebehely equation. We solve completely a special case of the inverse dynamics problem of constructing $U$ that generates a given family of conics known as Bertrand's problem. At the end we establish the relation between Bertrand's problem and the solutions to the Heun differential equation. We illustrate our results by several examples.