Method and system for non-linear modeling of physiological behavior, such as R-R intervals, in implantable devices, such as a rate responsive pacemakers, comprising a comprehensive modeling and optimization methodology based on fractional calculus and constrained finite horizon optimal control theory that allows for allows for fine-grain optimization of pacemaker response to heart rate variations and the theoretical basis on which a hardware implementation of the fractional optimal controller that can respond to changes in the heart rate dynamics. Present invention describes a fractal approach to pacemaker control based on the constrained finite horizon optimal control problem. This is achieved by modeling the heart rate dynamics via fractional differential equations. Also, by using calculus of variations, the invention describes how the constrained finite horizon optimal control problem can be reduced to solving a linear system of equations. Finally, the invention describes the theoretical basis on which a hardware implementation become possible.