码迷,mamicode.com
首页 > 其他好文 > 详细

寻找方程不动点

时间:2015-02-05 23:17:04      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:

const double tolerance = 0.00001;

bool CloseEnough (const double &val1
                  ,const double &val2)
{
    return (abs(val1 - val2) < tolerance);
}

double FixedPoint (function<double (const double&)> f
                   , const double &guess)
{
    const auto next = f (guess);
    if (CloseEnough (guess, next)) {
        return next;
    }
    else {
        return FixedPoint (f, next);
    }
}

int main ()
{
    cout << FixedPoint ([] (const double &x)
                        {return cos(x)+ sin(x);}
                        , 1.0);
    cout << endl;
    return 0;
}

 

寻找方程不动点

标签:

原文地址:http://www.cnblogs.com/wuOverflow/p/4276077.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!