Horner's rule for polynomial evaluation: Difference between revisions
Content deleted Content added
mNo edit summary |
Added a solution for MATLAB |
||
Line 277:
show horner 3 [-19 7 -4 6] ; 128</lang>
=={{header|MATLAB}}==
<lang MATLAB>function accumulator = hornersRule(x,coefficients)
accumulator = 0;
for i = (numel(coefficients):-1:1)
accumulator = (accumulator * x) + coefficients(i);
end
end</lang>
Output:
<lang MATLAB>>> hornersRule(3,[-19, 7, -4, 6])
ans =
128</lang>
=={{header|Objective-C}}==
|