平方根的逼近求值法

如何快速的求出平方根的数值

2 \sqrt{2} 2 的值如何求出

1. 基础运算过程

  1. 1.5 = ( 1 + 2 / 1 ) / 2 1.5 = (1 + 2/1) / 2 1.5=(1+2/1)/2
  2. 1.416667 = ( 1.5 + 2 / 1.5 ) / 2 1.416667 = (1.5 + 2/1.5) / 2 1.416667=(1.5+2/1.5)/2
  3. 1.41421468926554 = ( 1.416 + 2 / 1.416 ) / 2 1.41421468926554 = (1.416 + 2/1.416) / 2 1.41421468926554=(1.416+2/1.416)/2
  4. 1.41421356243813 = ( 1.4142 + 2 / 1.4142 ) / 2 1.41421356243813= (1.4142 + 2/1.4142) / 2 1.41421356243813=(1.4142+2/1.4142)/2

2. 过程解释

  1. a = ( a + b / a ) / 2 a = (a + b/a)/2 a=(a+b/a)/2
  2. 2 a = ( a + b / a ) 2a = (a + b/a) 2a=(a+b/a)
  3. 2 a 2 = a 2 + b 2a^2 = a ^ 2 + b 2a2=a2+b
  4. b = a 2 b = a ^ 2 b=a2

3. 数学上的同类方法

  1. 二分逼近法

使用该方法也可以求出 一元二次方程的根

4. C 语言递归实现,求平方根

#include <stdio.h>
#include <math.h>
double recursive_sqrt(double x, double base){
    double y, z;
    y = (base + x / base) / 2.0;
    printf("%f -- %f\n", y, base);
    if (fabs(y - base) > pow(0.1, 4)){
        z = recursive_sqrt(x, y);
    }
    else{
        z = y;
    }
    return z;
}
int main(int argc, char const *argv[])
{
    double n = 17.0;
    double x ;
    x = recursive_sqrt(n, 1.0);
    printf("%f", x);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_42290927/article/details/106453060
今日推荐