Horner's rule for polynomial evaluation: Difference between revisions
Content deleted Content added
Added a solution for MATLAB |
|||
Line 289: | Line 289: | ||
Output: |
Output: |
||
<lang MATLAB>>> hornersRule(3,[-19, 7, -4, 6]) |
<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 = |
ans = |