its been a while since I did this math, but isn't it just about taking a derivative and finding the relative minimum/maximum points of the function by where the derivative = 0? (I was on the engineering side of CS, so haven't touched calculus since my undergrad days).