Horner's rule for polynomial evaluation: Difference between revisions

(Added a solution for MATLAB)
Line 289:
Output:
<lang MATLAB>>> hornersRule(3,[-19, 7, -4, 6])
 
ans =
 
128</lang>
Matlab also has a built-in function "polyval" which uses Horner's Method to evaluate polynomials. The list of coefficients is in descending order of power, where as to task spec specifies ascending order.
<lang MATLAB>>> polyval(fliplr([-19, 7, -4, 6]),3)
 
ans =
Anonymous user