关于c++求根程序

来源:百度知道 编辑:UC知道 时间:2024/06/22 00:49:35
用弦截发求方程的根:f(x)=x^3-5*x^2+16*x-80=0,就是通过判断f(x1)*f(x2)的符号逼近根的方法,下面是程序error C2064: term does not evaluate to a function请指教:#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
double f(double);
double xpoint(double,double);
double root(double,double);
double f1,f2;
int main()
{
double x,x1,x2;
do
{cout<<"input x1,x2:"<<endl;
cin>>x1>>x2;
f1=f(x1);
f2=f(x2);}
while (f1*f2>=0);
x=root(x1,x2);
cout<<setiosflags(ios::fixed)<<setprecision(7);
cout<<"a root of the equation is"<<x<<endl;
return 0;
}

double f(double x)
{
double y;
y=x*x*x-5*x*x+16*x-80;
return y;
}

double xpoint(double x1,double x2)
{
double x;
x=(x1*f2-x2*f1)/(f2-f1);
return x;
}

把你在最后一个DO循环里面定义的double f的f改成其他字符,因为和函数f()歧义了,还有最有个也不是fabs(x),而是fabs(x1-x2)。。。即使改了还有错,夜深了,就不帮你看了,要睡觉了,你自己再琢磨吧