eval_poly Function

A function that evaluates a polynomial expression.

Include

<math.h>

Prototype

void eval_poly(double x, const double * d, int n);

Arguments
x
the indeterminates
d
the coefficient constants of the indeterminates
n
the order of the polynomial

Remarks

The eval_poly() function evaluates a polynomial of order n, whose coefficients are contained in the array d, at x, for example the second order polynomial:

y = x2*d[2] + x*d[1] + d[0].

Example

#include <math.h>
#include <stdio.h>

int main (void)
{
  double x, y;
  double d[3] = {1.1, 3.5, 2.7};

  x = 2.2;
  y = eval_poly(x, d, 2);
  printf(“The polynomial evaluated at %f is %f\n”, x, y);
}

Example Output

The polynomial evaluated at 2.2 is 23.468