fix bugs in optimalCurve.m