http://introcs.cs.princeton.edu/java/13flow/Sqrt.java.html:
public class Sqrt {
public static void main(String[] args) {
// read in the command-line argument
double c = Double.parseDouble(args[0]);
double epsilon = 1e-15; // relative error tolerance
double t = c; // estimate of the square root of c
// repeatedly apply Newton update step until desired precision is achieved
while (Math.abs(t - c/t) > epsilon*t) {
t = (c/t + t) / 2.0;
}
// print out the estimate of the square root of c
System.out.println(t);
}
}
问题是..我非常了解程序本身是如何工作的。我遇到的问题是方程 f(x) = x^2 - c 以及它与上面的代码的关系。比如,为什么将它除以 x 使得 x(x - c/x)?当涉及到其中一些示例时,似乎缺少数学解释。换句话说,我正在从简单的数学角度寻找解释,而不是编码那么多。