// http://guipn.com/blog
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
double evalpolynom(double x, unsigned degree, double *coefs)
{
double result = 0;
unsigned index;
for (index = 0; index <= degree; index++)
result += coefs[index] * pow(x, index);
return result;
}
int main(void)
{
double *pol = (double []) {50, -1, 2}; // 50 -x + 2x^2
printf("f(8) = 180: %f\n", evalpolynom(8, 2, pol));
return 0;
}
No replies to this topic
#1
Posted 15 May 2011 - 07:33 PM
I was rummaging through some old code of mine when I found this routine for determining a polynom's value given its degree, coeficients and a value for x (the variable). I hope it's useful to anyone:
|
|
|
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









