首页 > 其他 > 详细

结合之前博客中的代码产生的牛顿求根法

时间:2015-02-07 17:18:42      阅读:271      评论:0      收藏:0      [点我收藏+]
cdouble DX = 0.00001;

dFun Deriv (dFun g)
{
    return [g] ( cdouble &x)
               { auto delta_x = x + DX;
                 return (g(delta_x) - g(x)) / DX;};
}

dFun NewtonTransForm (dFun g)
{
    return [g] (cdouble &x)
               {return (x - (g(x) / (Deriv(g)(x))));};
}

double NewtonsMethod (dFun g, cdouble &guess)
{
    return FixedPoint (NewtonTransForm(g), guess);
}

double NewtonsSqrt (cdouble &x)
{
    return NewtonsMethod ([x] (cdouble &y)
                              {return (pow(y, 2) - x);}
                         , 1.0);
}

int main ()
{
    cout << NewtonsSqrt(121.04);
    cout << endl;
    return 0;
}

 

结合之前博客中的代码产生的牛顿求根法

原文:http://www.cnblogs.com/wuOverflow/p/4279037.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!