How to solve polynomial function?