# Recursive method to evaluate a polynomial

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?

-
What do you mean to solve a polynomial? Usually one solves equations. Do you want to factor it? Find a (or all) the roots? Most numerical analysis books will have a chapter on this. – Ross Millikan Jun 30 '11 at 17:30
Will any solution do, or do you want a particular one, or do you want all the solutions? Do you want a real solution, and if you do, do you know that such a solution exists in advance, or do you need to check? – Mark Bennet Jun 30 '11 at 17:31
Sorry for the confusion, I will be given the value of x as well (I've also edited the question). – George Jun 30 '11 at 17:44
Edits have clarified that the question was about evaluating the polynomial rather than solving it – Mark Bennet Jun 30 '11 at 18:54

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

Try using Horner's Method.

-
That does seem to be what is meant. – Mark Bennet Jun 30 '11 at 18:10

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

-
Euler's method is for solving differential equations. There is no differential equation here. – Robert Israel Jun 30 '11 at 18:16
@Robert: You know, you're right. I got my names mixed up. I meant Horner's Method (en.wikipedia.org/wiki/Horner_scheme) too. – mixedmath Jul 1 '11 at 3:09

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);


}

-