We all know how solve x2+x−1=0, for example. If we consider x4+x−3=0, then it is no longer clear how to compute the roots.
In addition, we saw that evaluating the quadratic formula for the roots a quadratic polynomial can itself be problematic. So, we develop methods that do not depend on any analytical structure, such as degree, of the polynomials
A polynomial of degree (or order) n is given by
P(x)=anxn+an−1xn−1+⋯+a1x+a0.The numbers {ai}ni=0 are called the coefficients.
The following gives us a theoretical justification for searching for the roots of P(x):
A polynomial P(x) with real or complex coefficients has n (possibly repeated and possibly complex) roots. Furthermore, for some (possibly complex) values x1,x2,…,xk, and integers m1,m2,…,mk
P(x)=an(x−x1)m1(x−x2)m2⋯(x−xk)mk,k∑j=1mk=n.Suppose P(x) and Q(x) are polynomials of degree n. If there are n+1 distict points x1,x2,…,xn+1 (on the real axis or in the complex plane) such that P(xi)=Q(xi), then P(x)=Q(x) for all x.
If we can prove the last claim then P(x0)=b0. So, consider
(x−x0)Q(x)+b0=xQ(x)−x0Q(x)+b0=bnxn+bn−1xn−1+⋯+b2x2+b1x−bnx0xn−1−bn−1x0xn−2−⋯−b2x0x−b1x0+b0Collecting the powers, we find
This gives an iterative method for computing P(x0). Now, to compute P′(x0):
P′(x)=Q(x)+(x−x0)Q′(x)⇒P′(x0)=Q(x0).So, as we apply Horner's method to compute P(x0), we also compute {bi} the coefficients of Q(x). So, we can apply Horner's method again to evaluate Q(x0).
Set bn=an, cn=bn.
For k=n−1,n−2,…,1 set
Set b0=a0+b1x0
Then b0=P(x0) and c1=Q(x0)=P′(x0).
a = [-1,1,-1,1,-1,1,1]; pow = [1:length(a)]-1;
b = a; c = a; % initialize b & c, just good programming practice
p = @(x) sum((x.^pow).*a);
dp = @(x) sum((x.^(pow(2:end)-1)).*a(2:end).*pow(2:end));
x0 = .5;
i = length(a);
while i > 2
i = i-1;
b(i) = a(i) + b(i+1)*x0;
c(i) = b(i) + c(i+1)*x0;
end
b(1) = a(1) + b(2)*x0;
c(2)-dp(x0)
b(1)-p(x0)
x = linspace(-1,1,100); y = x;
for i = 1:100
y(i)=p(x(i));
end
hold off; plot(x,y)
title('A plot of P(x)')
p0 = .1;
for j = 1:20;
i = length(a);
while i > 1
i = i-1;
b(i) = a(i) + b(i+1)*p0;
c(i) = b(i) + c(i+1)*p0;
end
p0 = p0 - b(1)/c(2);
end
p0
plot(x,y); hold on;
title('A plot of P(x)')
plot(x,0*x) % plot the x-axis
plot(p0,0,'ro') % plot the zero to see that we are computing it
Horner's method actually amounts to synthetic division. Compute P(2) where
P(x)=x4−2x3+x2−x+2using Horner's method.