我是比较新的C++编程,我有一个分配来编码牛顿拉夫逊法,但是我有错误的错误:错误:称为对象类型“双”不是一个函数或函数指针
called object type 'double' is not a function or function pointer
当我尝试编译我的代码时出现此错误。我尝试了一些基本的改变来分配指针,但是我可能是以错误的方式做了,我的代码打印在下面,有人可以解释我该如何克服这个问题?
#include <iostream>
#include <math.h>
using namespace std;
double f(double x); //this is f(x)
double f(double x) {
double eq1 = exp(x) + pow(x,3) + 5;
return eq1;
}
double f1(double x); //this is the first derivative f'(x)
double f1(double x) {
double eq2 = exp(x) + 3*pow(x,2);
return eq2;
}
int main() {
double x, xn, f, f1, eps;
cout << "Select first root :" << '\n'; //Here we select our first guess
cin >> xn;
cout << "Select Epsilon accuracy :" << '\n';
cin >> epsi;
f = f(x);
f1 = f1(x);
cout << "x_n" << " " << "x_(n+1)" << " " << "|x_(n+1) - x_1|" << '\n';
do {
x = xn; //This is the first iteneration step where x takes the value of the last itenarated (known) root xn
f = f(x);
f1 = f1(x);
xn = x - (f/f1); //this the formula that sets the itenaration going
cout << x << " " << xn << " " << fabs(xn - x) << '\n';
}
while(fabs(xn - x) < epsi); //If |x_(n+1) - x_n| is smaller than the desired accurcay than the itenaration continues
cout << "The root of the equation is " << xn << '\n';
return 0;
}
谢谢
你可以减少到一个[MCVE],请重现错误。 –
其中哪行是错误?你在说什么指针?顺便说一句,它是“迭代”而不是“iteneration” – user463035818
你不需要转发声明的功能,如果你不使用它们之前,他们被定义。 – user463035818