There are two questions there really : a) how can I compile user entered text and b) how do I convert a mathematical equation into code.

If you follow this link you'll find help on how to accept text at runtime and compile it. The second part I'll leave for someone else!