算法之【牛顿迭代法】

众所周知,计算机的基本数值算法是加减乘除,甚至只是加减法。而次方和开根算法都是由四则运算混合表示而成的,因而根号计算比四则运算要慢很多。无理数如√2的浮点数计算就是由牛顿迭代法得出的。牛顿迭代法是一种用于计算曲线方程根的精确算法(尤其是幂函数方程),比二分法更加高效,因为它基于微分。

As we all know, basic numerical calculation in the computer is: addition, subtraction, multiplication and division.

Or even only the addition and subtraction. But the power and root algorithm is a complex combination of the four fundamental operations, so they are much slower. Irrational numbers such as √2 whose floating point is obtained by the Newton-Raphson method. Newton-Raphson method is a precise algorithm used to calculate the curvilinear equation (especiallypower function), it’s more efficient than Dichotomy because it is based on the differential.

以计算√x(精度e)为例的c语言函数:

A example using C language calculating √x with precision ’e’:

double abs_value(double x)

{

 if(x<0)x=-x;

 return x;

}

double sqrt_root(double x,double e)

{

 double x0=1;

 while(abs_value(x0*x0-x)>e)

X0=(x0+x/x0)/2;

 return x0;

}


转载于:https://my.oschina.net/jinhengyu/blog/1572150

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值