Created
February 11, 2014 06:45
-
-
Save ThaisRobba/8930302 to your computer and use it in GitHub Desktop.
Polynomial function for Lua (outputs value based on a numbers table and an x value)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local sum = 0 | |
function polynomial(t, x) | |
--t is a table, x is the x value | |
for i=1, #t do | |
sum = sum+t[#t -i+1]*x^(i-1) --Travels in reverse through the table | |
end | |
return print(sum) --prints the result | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment