1
$\begingroup$

I want to find a recursive way of evaluating any polynomial (I'm given the polynomial, and a value for x, and I need to replace the x in the polynomial with the value). The polynomial can be anything, and the x-value will be an integer. Say, $3x^5+9x^3-2x^2+x$ and x=5.

What would be the most efficient way of computing the value?

  • 0
    Edits have clarified that the question was about evaluating the polynomial rather than solving it2011-06-30

3 Answers 3

7

Looks like you want to evaluate a polynomial at a given point.

Try using Horner's Method.

  • 0
    That does seem to be what is meant.2011-06-30
0

I recommend looking into [Horner's Method][1] and Newton's Method.

  • 0
    @Robert: You know, you're right. I got my names mixed up. I meant Horner's Method (http://en.wikipedia.org/wiki/Horner_scheme) too.2011-07-01
0

double p1(double s, double x, int n) / recursive version */ { double peval; int i;

if (n==0) return s[0]; else     return s[n]*power(x,n)+p1(s,x,n-1); 

}