You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-- Sure, if this is what you mean.
function polyval (p, x)
local sum, pow = 0, 1
for _, a in ipairs (p) do
sum = sum + a * pow
pow = pow * x
end
return sum
end
That would still be 2(n+1) multiplications. They mean this:
a0 + x*(a1 + x*(a2 + x*(a3 ...+ x*an)))))
which would look something like this:
function poly_eval2(p, x)
ret = p[#p]
for k = #p-1,1,-1 do
ret = ret * x
ret = ret + p[k]
end
return ret
end
The text was updated successfully, but these errors were encountered:
That would still be 2(n+1) multiplications. They mean this:
a0 + x*(a1 + x*(a2 + x*(a3 ...+ x*an)))))
which would look something like this:
The text was updated successfully, but these errors were encountered: