首页 > 代码库 > 连续函数的根

连续函数的根

#include <iostream>#include <math.h>double f(double const & x){    return 4 * x + 1;}double root(double (*f)(double const &), double a, double b, double const & e){    double middle = (a + b) / 2;    while(f(middle) != 0 && fabs(b - 1) > e)    {        if(f(a) * f(middle) < 0)        {            b = middle;        }        else        {            a = middle;        }        middle = (a + b) / 2;    }    return middle;}int main(){    std::cout << root(f, -20, 20, 0.001);    getchar();    return 0;}

 

技术分享

 

技术分享

 

技术分享

 

技术分享

连续函数的根