How to Optimize a Fitted Curve in MATLAB