This site works best with JavaScript enabled. Please enable JavaScript to get the best experience from this site.
0
0
0
I would like to implement the trapezoidal rule in Lua.
https://en.wikipedia.org/wiki/Trapezoidal_rule
I am not sure how to sum up each calculation.
My code:
example = {1,3,5,7}
pos_x = {0.0, 3.0, 6.0, 9.5}
for i = 1, #example do
if i + 1 > #example then
return -- exit out
end
local time_var = pos_x[i+1] - pos_x[i]
local value_var = example[i+1] + example[i]
tra_rule = ((time_var) * value_var/2)
print(tra_rule)
end
The calculation should be:
(3.0 - 0.0) * ((3+1)/2) + (6.0 - 3.0) * ((5+3)/2) + (9.5 - 6.0) * ((7+5)/2)
Do you guys have any idea ?
Best,
ecki891
0
0
Great job :)
Best,
ecki891
0
I am trying to multiply each element of an array list by its neighbor. I've tried to use a while loop to solve that issue.
As an example:
array_list = {1,3,5,7}
The result should be:
1 * 3 = 3
3 * 5 = 15
5 * 7 = 35
Code:
array_list = {1,3,5,7}
while array_list[i] do
if i <= table.getn(array_list) and i<=i+1 then
test_var = array_list[i] * array_list[i+1]
--term = math.sqrt(test_var)
end
end
print("Test var:" , test_var)
Do you have any suggestion ?
Best,
ecki891