finished the implementation of optimalParameter()