Reputation: 19
#include <math.h>
#include <stdio.h>
int main() {
double x0, x, eps, dx, r;
x0 = 0.60000;
x = x0;
eps = 0.0001;
do {
r = x + pow(x, 1 / 2) + pow(x, 1 / 3) - 2.5;
dx = (r / (1 - 1 / 2 (x , -1 / 2) + 1/3 (x, -1 / 3)));
x = (x - dx);
} while ((abs(dx)) > eps);
printf("%f %f\n", x, r);
return 0;
}
*error: called object is not a function or function pointer * the code does not work, what needs to be done to make everything right
Upvotes: 1
Views: 110
Reputation: 12404
You have tons of syntax and semantic errors:
pow(x, 1 / 2)
Here 1/2
does integer division which means that the resulting 0.5
is chopped to 0
.
To get floating point results you must ensure that at least one operand is a floating type like 1.0/2
.
Then you have a similar piece
1/2(x,-1/2)
Again, due to integer division -1/2
evaluates to 0
.
Furthermore you are missing some operator before the brackets.
That means the compiler expects some function call.
But 2
is not a function. That is probably the place where you get your error message.
If you use ,
in other situations than a parameter list or variable definition list, it is taken as a "comma operator" that evaluates to the second operand. That means (x,-1/2)
evaluates to (-1/2)
which again evaluates to 0
.
In this case I have no idea what you want to achieve with that expression and cannot give some fix for that.
Finally, you use a function that is not suitable for floating point numbers and don't provide a prototype for it as well:
abs(dx)
You should use fabs
instead.
Usage of abs
is also broken because it requires header stdlib.h
which you do not include.
Upvotes: 2