Horner's Method for Polynomial Evaluation | GeeksforGeeks
Given a polynomial of the form cnxn + cn-1xn-1 + cn-2xn-2 + … + c1x + c0 and a value of x, find the value of polynomial for a given value of x. Here cn, cn-1, .. are integers (may be negative) and n is a positive integer.
Horner’s method can be used to evaluate polynomial in O(n) time. To understand the method, let us consider the example of 2x3 – 6x2 + 2x – 1. The polynomial can be evaluated as ((2x – 6)x + 2)x – 1. The idea is to initialize result as coefficient of xn which is 2 in this case, repeatedly multiply result with x and add next coefficient to result. Finally return result.
http://www.math10.com/en/algebra/horner.html
Read full article from Horner's Method for Polynomial Evaluation | GeeksforGeeks
Given a polynomial of the form cnxn + cn-1xn-1 + cn-2xn-2 + … + c1x + c0 and a value of x, find the value of polynomial for a given value of x. Here cn, cn-1, .. are integers (may be negative) and n is a positive integer.
Horner’s method can be used to evaluate polynomial in O(n) time. To understand the method, let us consider the example of 2x3 – 6x2 + 2x – 1. The polynomial can be evaluated as ((2x – 6)x + 2)x – 1. The idea is to initialize result as coefficient of xn which is 2 in this case, repeatedly multiply result with x and add next coefficient to result. Finally return result.
// returns value of poly[0]x(n-1) + poly[1]x(n-2) + .. + poly[n-1]
int
horner(
int
poly[],
int
n,
int
x)
{
int
result = poly[0];
// Initialize result
// Evaluate value of polynomial using Horner's method
for
(
int
i=1; i<n; i++)
result = result*x + poly[i];
return
result;
}
http://www.math10.com/en/algebra/horner.html
f(x0) = a0 + a1x0 + a2x02 + ... + anx0n
This can, also, be written as:
f(x0) = a0 + x0(a1 + x0(a2 + x0(a3 + ... + (an-1 + anx0)....)
f(x) = a0 + a1x + a2x2 + a3x3 + a4x4 + a5x5
which can be evaluated at x = x0 by re-arranging it as:
f(x0) = a0 + x0(a1 + x0(a2 + x0(a3 + x0(a4 + a5x0))))
http://n1b-algo.blogspot.com/2010/02/polynomial-evaluation.htmlRead full article from Horner's Method for Polynomial Evaluation | GeeksforGeeks