I use the library <Math>
. You need to specify a formula by which each term will be consistent ( -3-4x-5x^2...
).
for(d=-3;n=1;n++) { d=d*xx^n }
How to set x ^ n?
I use the library <Math>
. You need to specify a formula by which each term will be consistent ( -3-4x-5x^2...
).
for(d=-3;n=1;n++) { d=d*xx^n }
How to set x ^ n?
Exponentiation:
#include <cmath> double res = pow (x, n);
By the way, which platform and compiler?
And another thing: if you build to an integer degree (especially a small one), then it’s faster just to multiply the numbers.
In your case, the poly (...) function from math.h is useful.
Well, dear @mikillskegg , without poly ():
double Polynom(const double x, const int n) { double R = 3.0, powX = 1.0; for(int i = 1; i <= n; i++) { powX *= x; R += (i + 3) * powX; } return -R; }
Source: https://ru.stackoverflow.com/questions/59983/
All Articles