operations needed for polynomial evaluation

%EVALPOL counts operations needed for polynomial evaluation.
%       The program calls the function EVALPOL1 for a term
%       by term scheme, and the function EVALPOL2 for
%       Horner’s scheme.
%       See Example 7.3, The complexity of polynomial evaluation.

x = 5; count1 = zeros(1, 10); count2 = zeros(1, 10);
value = zeros(1, 10);value1 = zeros(1, 10);
value2 = zeros(1, 10);
for n = 1:10
c = rand(1, n+1); value(n) = polyval(c, x);
flops(0), value1(n) = evalpol1(c, x);
count1(n) = flops;
flops(0), value2(n) = evalpol2(c, x);
count2(n) = flops;
end
n = 1: 10;
[ n’ count1′ count2′ ]
pause
plot(n, count1, n, count2)
xlabel(‘Degree of polynomial’), ylabel(‘Number of flops’)
text(n(5), count1(5), ‘simple algorithm’)
text(n(5), count2(5), ‘Scheme of Horner’)