In this paper is presented basic elements of the optimal control theory and a realtime optimal control for a physical system. This methodology makes a feedback of the state variables trough a neural-control law. The control system keep on the physical system in a fixed trajectory. The paper also shows any concepts in variational calculus and their interaction with neural nets. The practical experience and simulations shows the capability of the control system to reject perturbations and parametric variations on the physical system.