Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|cite|improve this question
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
up vote 7 down vote accepted

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

Try using Horner's Method.

share|cite|improve this answer
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.

share|cite|improve this answer
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 ( 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];
    return s[n]*power(x,n)+p1(s,x,n-1);


share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.