„Modul:Math“ – Versionsunterschied
Erscheinungsbild
[gesichtete Version] | [gesichtete Version] |
Inhalt gelöscht Inhalt hinzugefügt
KKeine Bearbeitungszusammenfassung |
KKeine Bearbeitungszusammenfassung |
||
Zeile 24: | Zeile 24: | ||
end |
end |
||
end |
end |
||
local function tanh(x) |
local function tanh(x) |
||
Zeile 33: | Zeile 32: | ||
local c = cosh(x); |
local c = cosh(x); |
||
if c ~= 0 then |
if c ~= 0 then |
||
local value = |
local value = s / c |
||
if value then |
if value then |
||
return value, true |
return value, true |
||
Zeile 44: | Zeile 43: | ||
end |
end |
||
local function coth(x) |
|||
-- Kotangens hyperbolicus |
|||
x = tonumber(x) or false; |
|||
if not x then return 0, false; end |
|||
local s = sinh(x); |
|||
local c = cosh(x); |
|||
if s ~= 0 then |
|||
local value = c / s; |
|||
if value then |
|||
return value, true |
|||
else |
|||
return 0, false |
|||
end |
|||
else |
|||
return 0, false |
|||
end |
|||
end |
|||
local Math = { }; |
local Math = { }; |
||
Zeile 80: | Zeile 96: | ||
if data then |
if data then |
||
local value, isOk = tanh(data); |
local value, isOk = tanh(data); |
||
if isOk then |
|||
return tostring(value); |
|||
else |
|||
return "" -- error |
|||
end |
|||
else |
|||
return "" -- error |
|||
end |
|||
end |
|||
function Math.coth( frame ) |
|||
local data = tonumber(frame.args[1]) or false; |
|||
if data then |
|||
local value, isOk = coth(data); |
|||
if isOk then |
if isOk then |
||
return tostring(value); |
return tostring(value); |
Version vom 21. September 2024, 03:03 Uhr
Modul zur Berechnung mathematischer Funktionen, welche nicht im WP-Standard enthalten sind. Bei erlaubten Argumenten wird das Ergebnis zurückgegeben, ansonsten eine leere Zeichenkette.
Zurzeit implementiert:
- Math.sinh: Sinus hyperbolicus
- Math.cosh: Kosinus hyperbolicus
- Math.tanh: Tangens hyperbolicus
- Math.coth: Kotangens hyperbolicus
- Math.arsinh: Area Sinus hyperbolicus
- Math.arcosh: Area Kosinus hyperbolicus
- Math.artanh: Area Tangens hyperbolicus
- Math.arcoth: Area Kotangens hyperbolicus
local function sinh(x)
-- Sinus hyperbolicus
x = tonumber(x) or false;
if not x then return 0, false; end
local value = (math.exp (x) - math.exp (0 - x)) / 2
if value then
return value, true
else
return 0, false
end
end
local function cosh(x)
-- Cosinus hyperbolicus
x = tonumber(x) or false;
if not x then return 1, false; end
local value = (math.exp (x) + math.exp (0 - x)) / 2
if value then
return value, true
else
return 1, false
end
end
local function tanh(x)
-- Tangens hyperbolicus
x = tonumber(x) or false;
if not x then return 0, false; end
local s = sinh(x);
local c = cosh(x);
if c ~= 0 then
local value = s / c
if value then
return value, true
else
return 0, false
end
else
return 0, false
end
end
local function coth(x)
-- Kotangens hyperbolicus
x = tonumber(x) or false;
if not x then return 0, false; end
local s = sinh(x);
local c = cosh(x);
if s ~= 0 then
local value = c / s;
if value then
return value, true
else
return 0, false
end
else
return 0, false
end
end
local Math = { };
function Math.sinh( frame )
local data = tonumber(frame.args[1]) or false;
if data then
local value, isOk = sinh(data);
if isOk then
return tostring(value);
else
return "" -- error
end
else
return "" -- error
end
end
function Math.cosh( frame )
local data = tonumber(frame.args[1]) or false;
if data then
local value, isOk = cosh(data);
if isOk then
return tostring(value);
else
return "" -- error
end
else
return "" -- error
end
end
function Math.tanh( frame )
local data = tonumber(frame.args[1]) or false;
if data then
local value, isOk = tanh(data);
if isOk then
return tostring(value);
else
return "" -- error
end
else
return "" -- error
end
end
function Math.coth( frame )
local data = tonumber(frame.args[1]) or false;
if data then
local value, isOk = coth(data);
if isOk then
return tostring(value);
else
return "" -- error
end
else
return "" -- error
end
end
return Math