How to Find Maximum and Minimum of a Function