zoukankan      html  css  js  c++  java
  • 算法之【牛顿迭代法】

    众所周知,计算机的基本数值算法是加减乘除,甚至只是加减法。而次方和开根算法都是由四则运算混合表示而成的,因而根号计算比四则运算要慢很多。无理数如√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;

    }


  • 相关阅读:
    角色扮演游戏引擎的设计原理
    游戏服务器架构
    小谈网络游戏同步
    What is the single most influential book every programmer should read?
    Research Scientists and Engineers
    关于为什么不推荐使用用户定义表类型的说明
    程序员必须遵守的编程原则
    CacheStrategy缓存
    正能量
    MEF 和 MAF
  • 原文地址:https://www.cnblogs.com/jinhengyu/p/7517102.html
Copyright © 2011-2022 走看看