Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to do repeating equasions?

I'm writing code for an AI that has a part to do with sound.

local dB = 10 * math.log10(10^(L1 / 10) + 10^(L2 / 10) + 10^(L3 / 10))

I want 10^(L#/10) to repeat for however many "L"s there are. In the equasion im refrencing its written as 10^(L3/10) + ··· + 10^(L#/10). How can I do this in lua?

3 comments

0

what is L supposed to be? is it a function of another number or just an integer going from 1 to a number

0

"L1, L2, ... L# = sound pressure level of the separate sources in dBSPL" Is what the source says. Does that help? I'm getting it from a list of sound emitters in a folder with GetChildren.

0

Oh okay that makes more sense

1 answer

Assuming your L's are defined by you already, all you need to do is create a table and a loop. This can be done by doing the following:

local L_table = {
	--Your L1 value,
	--Your L2 value,
	--Your L3 value,
	--L4 and so on,
}

local LogSum = 0

for Lnum, Value in pairs(L_table) do
	LogSum = LogSum+(10^(Value/10))
end

local dB = 10*math.log10(LogSum)

You can keep adding L values into L_table, and the loop will sum all of the logs for you

2 comments

0

Will I have to manualy add a line of code in the table for each possible sound? The number of sounds I will need to calculate can fluctuate from 1 to 500+.

0

No, his example L_table is just to show you the structure. You'd create this array at runtime from wherever you're getting your L# values from, not hard code it like this.

This discussion is preserved as it was. New answers, comments, and votes are closed.