This paper describes the use of a hybrid algorithm of optimal control for a class of mechanical, under-actuated, nonlinear systems having fewer control inputs than degrees of freedom, like Inverted Pendulum (IP), when sampling frequency of the measurable state variables is near the frequency in which folding phenomenon happens. In this algorithm the online adaptive recognition of the system is essential and to implement the algorithm on a digital controller a computational algorithm of inverse Z-transform is presented to apply on the microprocessor-based controllers.