算法之【牛顿迭代法】
2018-01-05 11:05
204 查看
众所周知,计算机的基本数值算法是加减乘除,甚至只是加减法。而次方和开根算法都是由四则运算混合表示而成的,因而根号计算比四则运算要慢很多。无理数如√2的浮点数计算就是由牛顿迭代法得出的。牛顿迭代法是一种用于计算曲线方程根的精确算法(尤其是幂函数方程),比二分法更加高效,因为它基于微分。
以计算√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;
}
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;
}
相关文章推荐
- 关于使用牛顿迭代法和二分法解方程的算法说明
- 【算法王道】二分法和牛顿迭代法求平方根
- 【算法】牛顿迭代法
- 算法之【牛顿迭代法】
- C语言之基本算法11—牛顿迭代法求平方根
- 算法 牛顿迭代法(一定精度内实现sqrt)
- 算法之【牛顿迭代法】
- 算法之【牛顿迭代法】
- 算法 - 牛顿迭代法求平方根
- 算法之【牛顿迭代法】
- 算法之【牛顿迭代法】
- C语言之基本算法25—牛顿迭代法求方程近似根
- 关于使用牛顿迭代法和二分法解方程的算法说明
- 算法学习--日记(牛顿迭代法)
- 算法1.1 最大公约数(欧几里得)&判定素数&计算平方根(牛顿迭代法)
- 分类-1-逻辑回归(Logistic regression)、感知学习算法(perceptron learning algorithm)、牛顿迭代法
- C语言之基本算法11—牛顿迭代法求平方根
- C语言之基本算法25—牛顿迭代法求方程近似根
- 算法第四版入门:牛顿迭代法
- Adaboost 算法的原理与推导