Added code to compute optimal error. Solving the non-linear equations is a little, slow, could be made faster by just bounding as the function seems monotonic