Optimal control of singular systems via orthogonal functions