Scala: Newton's method.