Development of a new self-tuning control algorithm for finite and infinite horizon quadratic adaptive optimization