Module:Harmonics in equal: Difference between revisions
ArrowHead294 (talk | contribs) mNo edit summary |
+ link to Error page |
||
| (15 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local utils = require("Module:Utils") | local utils = require("Module:Utils") | ||
local yesno = require("Module:yesno") | |||
-- direct mapping | -- direct mapping | ||
| Line 27: | Line 28: | ||
end | end | ||
local tpri = {"! colspan=\"2\" | Harmonic "} | local tpri = {"! colspan=\"2\" | Harmonic "} | ||
local tabs = {"! rowspan=\"2\" | Error \n! Absolute ([[cent|¢]]) "} | local tabs = {"! rowspan=\"2\" | Error \n! [[Error|Absolute]] ([[cent|¢]]) "} | ||
local trel = {"! [[Relative interval error|Relative]] ([[relative cent|%]]) "} | local trel = {"! [[Relative interval error|Relative]] ([[relative cent|%]]) "} | ||
local tdeg | local tdeg | ||
if reduction then | if reduction then | ||
tdeg = {"! colspan=\"2\" | Steps<br>([[octave reduction|reduced]])"} | tdeg = {"! colspan=\"2\" | Steps<br />([[octave reduction|reduced]])"} | ||
else | else | ||
tdeg = {"! colspan=\"2\" | Step"} | tdeg = {"! colspan=\"2\" | Step"} | ||
end | end | ||
local fmt_abs = string.format(" %%+.%df", prec) | local fmt_abs = string.format("%%+.%df", prec) | ||
local fmt_rel = " %+.1f" | local fmt_rel = "%+.1f" | ||
local equave = math.log(num/denom) / math.log(2) | local equave = math.log(num/denom) / math.log(2) | ||
for _, p in pairs(intervals) do | for _, p in pairs(intervals) do | ||
s = math.log(p) / math.log(num/denom) | s = math.log(p) / math.log(num/denom) | ||
v = s*steps | v = s * steps | ||
ev = math.floor(v + 0.5) | ev = math.floor(v + 0.5) | ||
table.insert(tpri, "" .. p) | table.insert(tpri, "" .. p) | ||
| Line 53: | Line 54: | ||
local titleMarkup = "" | local titleMarkup = "" | ||
if title then | if title then | ||
titleMarkup = " | titleMarkup = "|+ style=\"font-size: 105%; white-space: nowrap;\" | " .. title .. "\n" | ||
end | end | ||
thead = thead .. | |||
titleMarkup .. | titleMarkup .. | ||
"|-\n | "|-\n" .. | ||
table.concat(tpri, " | table.concat(tpri, "\n! ") .. "\n" .. | ||
"|-\n | "|-\n" .. | ||
table.concat(tabs, " | table.concat(tabs, "\n| ") .. "\n" .. | ||
"|-\n | "|-\n" .. | ||
table.concat(trel, " | table.concat(trel, "\n| ") .. "\n" .. | ||
"|-\n | "|-\n" .. | ||
table.concat(tdeg, " | table.concat(tdeg, "\n| ") .. "\n" .. | ||
"|}" | "|}" | ||
return thead | |||
end | end | ||
local intervals = {} | local intervals = {} | ||
intervals.prime = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229 } | intervals.prime = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251 } | ||
intervals.odd = {3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 123, 125, 127 } | intervals.odd = {3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 125, 127 } | ||
intervals.integer = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128 } | intervals.integer = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128 } | ||
| Line 108: | Line 111: | ||
-- option intervals | -- option intervals | ||
local select_intervals = "integer" | local select_intervals = "integer" | ||
local name = steps .. "ed" .. num .. "/" .. denom | local name = steps .. "ed" .. num .. "/" .. denom | ||
| Line 125: | Line 127: | ||
end | end | ||
end | end | ||
if num == 3 and denom == 2 then | if num == 3 and denom == 2 then | ||
name = steps .. "edf" | name = steps .. "edf" | ||
| Line 131: | Line 134: | ||
-- override default intervals | -- override default intervals | ||
if frame.args["intervals"] and string.len(frame.args["intervals"]) > 0 then | if frame.args["intervals"] and string.len(frame.args["intervals"]) > 0 then | ||
select_intervals = frame.args[ | select_intervals = frame.args["intervals"] | ||
end | end | ||
if select_intervals == "odd" then | if select_intervals == "odd" then | ||
title_intervals = "odd harmonics" | title_intervals = "odd harmonics" | ||
elseif select_intervals == "integer" then | elseif select_intervals == "integer" then | ||
title_intervals = "harmonics" | title_intervals = "harmonics" | ||
else | |||
title_intervals = "prime harmonics" | |||
end | end | ||
local title = frame.args[ | local title = frame.args["title"] | ||
if title == nil or string.len(title) == 0 then | if title == nil or string.len(title) == 0 then | ||
title = "Approximation of ".. title_intervals .. " in " .. name | title = "Approximation of ".. title_intervals .. " in " .. name | ||
| Line 151: | Line 155: | ||
reduction = false | reduction = false | ||
end | end | ||
local collapsed = utils.value_provided(frame.args["collapsed"]) | local collapsed = utils.value_provided(frame.args["collapsed"]) | ||
local debugg = yesno(frame.args["debug"]) | |||
local result = approx(steps, num, denom, {unpack(intervals[select_intervals], start, start + columns - 1)}, title, prec, reduction, collapsed) | |||
if debugg == true then | |||
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>" | |||
end | |||
return | return frame:preprocess(result) | ||
end | end | ||
return p | return p | ||