Wrong binary expression with double

Hi :)

I am trying to implement a numerical approximation, but first I need to define the function and its first derivative. This is my code for the first derivative:

double Runge_der(double x)
{
double y=-(50*x)/(((25*x*x)+1)^2);
return y;
}

It shows a mistake in the definition of y, as "invalid operands to binary expression (double and double)", but I can't really find where the mistake is, because having first defined the original function as:


double Runge(double x)
{
double y;
y=1/((25*x*x)+1);
return y;
}

I didn't get any problems. If you could help me realize where the problem is, it would be extremely helpful.
Thanks :)
^ does not mean exponentiation. In C++ and other similar languages (like Python, Java, C#), it means binary XOR (exclusive OR).

Change ((25*x*x)+1)^2
to pow(25*x*x + 1, 2)
or (25*x*x + 1)*(25*x*x + 1)
or equivalent.

If you use pow, #include <cmath> .
Last edited on
1
2
double y=-(50*x)/(((25*x*x)+1)^2);
______________________________^

^ is the XOR operator, not an exponentiation operator.

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Last edited on
Topic archived. No new replies allowed.