背后巴比伦平方根法数学 [英] Mathematics behind Babylonian Square Root method

查看:184
本文介绍了背后巴比伦平方根法数学的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读法计算的任何数量的平方根和算法如下:

 双findSquareRoot(INT N){
    双X = N;
    双Y = 1;
    双E = 0.00001;
    而(X-Y> = E){
        X =(X + Y)/ 2;
        Y = N / X;
    }
    返回X;
}
 

我的关于这种方法的问题是

  1. 它是如何计算平方根?我不明白这背后的数学。如何 X =(X + Y)/ 2和y = N / X 收敛到n的平方根。解释这一数学。

  2. 什么是算法的复杂性?

解决方案

这是很容易看到,如果你做一些运行和打印x和y的连续值。例如,对于100:

  50.5 1.9801980198019802
26.24009900990099 3.8109612300726345
15.025530119986813 6.655339226067038
10.840434673026925 9.224722348894286
10.032578510960604 9.96752728032478
10.000052895642693 9.999947104637101
10.000000000139897 9.999999999860103
 

见,关键是,如果 X 不可以的平方根 N ,那么它是高于或低于实际的根,并 N / X 总是在另一侧。所以,如果你计算的中点 X N / X 这将在某种程度上更接近真正的根。

和有关的复杂性,它实际上是无界的,因为真正的根永远不会达到。这就是为什么你的电子参数。

I read the method to calculate the square root of any number and the algorithm is as follows:

double findSquareRoot(int n) {
    double x = n;
    double y = 1;
    double e = 0.00001;
    while(x-y >= e) {
        x = (x+y)/2;
        y = n/x;
    }
    return x;
}

My question regarding this method are

  1. How it calculates the square root? I didn't understand the mathematics behind this. How x=(x+y)/2 and y=n/x converges to square root of n. Explain this mathematics.

  2. What is the complexity of this algorithm?

解决方案

It is easy to see if you do some runs and print the successive values of x and y. For example for 100:

50.5 1.9801980198019802
26.24009900990099 3.8109612300726345
15.025530119986813 6.655339226067038
10.840434673026925 9.224722348894286
10.032578510960604 9.96752728032478
10.000052895642693 9.999947104637101
10.000000000139897 9.999999999860103

See, the trick is that if x is not the square root of n, then it is above or below the real root, and n/x is always on the other side. So if you calculate the midpoint of x and n/x it will be somewhat nearer to the real root.

And about the complexity, it is actually unbounded, because the real root will never reached. That's why you have the e parameter.

这篇关于背后巴比伦平方根法数学的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆