Algorithm for the classic dual cosine equation