Module:Temperament data

Revision as of 07:31, 15 October 2023 by CompactStar (talk | contribs) (https://aalexan3.math.ncsu.edu/articles/mat-inv-rep.pdf)
Module documentation[view] [edit] [history] [purge]
This module should not be invoked directly; use its corresponding template instead: Template:Temperament data.
Module:Temperament data is a draft module. It is incomplete and may not be in active development. If possible, editors are encouraged to help with its development. In the meantime, editors should avoid using this module across the Xenharmonic Wiki, except for testing.
Introspection summary for Module:Temperament data 
Functions provided (1)
Line Function Params
69 matinv (a)
Lua modules required (1)
Variable Module Functions used
rat Module:Rational dependency not used

No function descriptions were provided. The Lua code may have further information.


local rat = require('Module:Rational')
local p = {}

-- Complex number functions (1st element = real and 2nd element = imaginary)
local function cadd(a, b)
	return {(a[1] + b[1]), (a[2] + b[2])}
end

local function csub(a, b)
	return {(a[1] - b[1]), (a[2] - b[2])}
end

local function cmul(a, b)
	return {(a[1] * b[1] - a[2] * b[2]), (a[1] * b[2] + a[2] * b[1])}
end

local function cdiv(a, b)
	return {(a[1] * b[1] + a[2] * b[2])/(b[1]*b[1] + b[2]*b[2]), (a[2] * b[1] - a[1] * b[2])/(b[1]*b[1] + b[2]*b[2])}
end

local function matadd(a, b)
	local result = {}
	for i = 1, #a  do
		result[i] = {}
		for j = 1, #(b[1]) do
			result[i][j] = cadd(a[i][j], b[i][j])
		end
	end
	return result
end

local function matsub(a, b)
	local result = {}
	for i = 1, #a  do
		result[i] = {}
		for j = 1, #(b[1]) do
			result[i][j] = csub(a[i][j], b[i][j])
		end
	end
	return result
end

local function matmul(a, b)
	local result = {}
	for i = 1, #a  do
		result[i] = {}
		for j = 1, #(b[1]) do
			result[i][j] = {0, 0}
			for k = 1, #(a[1]) do
				result[i][j] = cadd(result[i][j], cmul(a[i][k], b[k][j]))
			end
		end
	end
	return result
end


local function scalarmatmul(a, b)
	local result = {}
	for i = 1, #a  do
		result[i] = {}
		for j = 1, #(a[1]) do
			result[i][j] = cmul(a[i][j], b)
		end
	end
	return result
end

function p.matinv(a)
	dbl_identity = {}
	for i = 1, #a do
		dbl_identity[i] = {}
		for j = 1, #a do
			if i == j then
				dbl_identity[i][j] = {2, 0}
			else
				dbl_identity[i][j] = {0, 0}
			end
		end
	end
	
	xn = scalarmatmul(a, {0.0001, 0})
	
	for i = 1, 30 do
		xn = matmul(xn, matsub(dbl_identity, matmul(a, xn)))
	end
	return xn
end

return p