Jump to content

Horner's rule for polynomial evaluation: Difference between revisions

Added a solution for MATLAB
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}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.