john315
john315

Reputation: 27

How to write this math equation into c++

I don't know how to write the formula given in C++ and I cant use short cuts. I have to write the code in long version this is what I have so far

        4x^3 + 8x^2 + 9x - 18
y = --------------------------
       |7 – x^3| + √(3x^2 + 18)

| | means absolute value

It needs to be in a format like this (this is an example from my book):

double y = ((-4.0 * pow(x, 3.0)) + (8.0 * pow(x, 2.0) - (9.0 * x) + 18.0)) / (abs(7.0 - pow(x, 3.0)) + (sqrt(3.0) * pow(x, 2.0) + 10.0)); 

Upvotes: 0

Views: 21130

Answers (1)

IKavanagh
IKavanagh

Reputation: 6187

Your solution is very nearly there. However, if I've understood your equation correctly this should be correct.

double y = (4.0 * pow(x, 3.0) + 8.0 * pow(x, 2.0) + 9.0 * x - 18.0) / (std::abs(7.0 - pow(x, 3.0)) + sqrt(3.0 * pow(x, 2.0) + 18));

Upvotes: 1

Related Questions