跳至內容

模組:Complex Number/Matrix/doc

本頁使用了標題或全文手工轉換
維基百科,自由的百科全書

此頁面為 Module:Complex Number/Matrix 的說明文件

本模組為基於Module:Complex Number的矩陣運算庫

使用方法

[編輯]

LUA

[編輯]
函數庫初始化
  • local 自訂函數庫名稱 = require("Module:Complex Number/Matrix").mmath.init()
    例如:local mmath = require("Module:Complex Number/Matrix").mmath.init()
宣告矩陣
  • local 變數名稱 = 自訂函數庫名稱.matrix(自訂函數庫名稱.row(數字, 數字, 數字...),自訂函數庫名稱.row(數字, 數字, 數字...)...)
  • local 變數名稱 = 自訂函數庫名稱.toMatrix("{{數字, 數字, 數字...},{數字, 數字, 數字...},{數字, 數字, 數字...}...}")
    例如:
    local matrix1 = mmath.matrix(
    	mmath.row(1,2,3),
    	mmath.row(4,5,6),
    	mmath.row(7,8,9)
    )
    local matrix2 = mmath.toMatrix("{{1,2,3},{4,5,6},{7,8,9}}")
    
執行運算
例如:
local A = mmath.matrix(
	mmath.row(1,2,3),
	mmath.row(4,5,6),
	mmath.row(7,8,9)
)
print(A * A)
輸出:{{30,36,42},{66,81,96},{102,126,150}}
或者使用函數庫內容:
local mmath = require("Module:Complex Number/Matrix").mmath.init()
local A = mmath.matrix(
	mmath.row(1,2),
	mmath.row(3,4)
)
print(mmath.inverse(A))
輸出:{{-2,1},{1.5,-0.5}}

模板

[編輯]

使用{{複變運算}}

語法:{{複變運算|運算式|number class=Module:Complex Number/Matrix.mmath}}
宣告矩陣
語法:{{複變運算|matrix(row(數字, 數字, ...),row(數字, 數字, ...),...)|number class=Module:Complex Number/Matrix.mmath}}
例如:{{複變運算|matrix(row(1,2,3),row(4,5,6),row(7,8,9))|number class=Module:Complex Number/Matrix.mmath}}
→「{{1,2,3},{4,5,6},{7,8,9}}」
顯示矩陣(於{{計算結果}})
語法:{{計算結果|mathform(矩陣運算式)|number class=Module:Complex Number/Matrix.mmath}}
例如:{{計算結果|mathform(matrix(row(1,2,3),row(4,5,6),row(7,8,9)))|number class=Module:Complex Number/Matrix.mmath}}
→「[123456789]=[123456789]」
矩陣運算
例如:{{計算結果|mathform(matrix(row(1,2),row(4,5))*matrix(row(4,3),row(2,1)))|number class=Module:Complex Number/Matrix.mmath}}
→「[1245]×[4321]=[852617]」
例如:{{計算結果|det(matrix(row(1,2,5),row(4,3,6),row(7,9,8)))|number class=Module:Complex Number/Matrix.mmath}}
→「det⁡[125436798]=65」
例如:{{計算結果|mathform(inverse(matrix(row(1,2),row(3,4))))|number class=Module:Complex Number/Matrix.mmath}}
→「[1234]−1=[−211.5−0.5]」
矩陣數列:{{數列|<nowiki>{{#tag:math|$\ }}</nowiki>,|1|5|mathform(identity(x))| delnowiki=yes|preprocess=yes|raw_value=yes|class=Module:Complex Number/Matrix.mmath}}
→「$ , $ , $ , $ , $ , 」
矩陣數列 例2:{{數列|<nowiki>{{#tag:math|$\ }}</nowiki>,|1|4|mathform(last(1)*last(1))| delnowiki=yes|preprocess=yes|raw_value=yes|class=Module:Complex Number/Matrix.mmath|last1={ {1,2}, {3,4} } }}
→「$ , 0 , 0 , 0 , 」

函數列表

[編輯]
函數 名稱 別名 說明 math輸出
determinant 行列式 det 計算矩陣的行列式
參數:determinant(矩陣)
det⁡[1234]=−2
adjoint 伴隨矩陣 adj 計算矩陣的伴隨矩陣
參數:adjoint(矩陣)
adj⁡[1234]=[4−2−31]
cofactor 餘子式 cof 計算矩陣的餘子式
參數:cofactor(矩陣, i, j)
(cof[123456789])1,1=[5689]
mathform <math></math>輸出 令矩陣在tostring時是以<math></math>的格式輸出
參數:mathform(矩陣)
[abcd]
rows rows數 計算矩陣的rows數
參數:rows(矩陣)
rows([123456])=3
cols cols數 計算矩陣的cols數
參數:cols(矩陣)
cols([123456])=2
MatrixFunction 矩陣函數 對矩陣套用矩陣函數,僅支援4×4或以下的矩陣
參數:MatrixFunction(函數, 矩陣)
MatrixFunction(inverse,[1234])=[−211.5−0.5]
GaussElimination 高斯消去法 對矩陣做高斯消去法
參數:GaussElimination(矩陣)
GaussElimination([71421355642496328])=[49632801122007]
rank 秩 計算矩陣的秩
參數:rank(矩陣)
rank([123456789])=2
transpose 轉置矩陣 計算矩陣的轉置
參數:transpose(矩陣)
[1234]T=[1324]
inverse 反矩陣 計算矩陣的反矩陣
參數:inverse(矩陣)
[1234]−1=[−211.5−0.5]
clone 複製一份矩陣物件
參數:clone(矩陣)
identity 單位矩陣 取得n×n的單位矩陣
參數:identity(維度)
I3=[100010001]
diag 對角矩陣 產生對角矩陣
參數:diag(a, b, c,...對角矩陣的值)
diag⁡(1,2,3,4)=[1000020000300004]
eigenvalue 特徵值 計算矩陣的特徵值,僅支援4×4或以下的矩陣
參數:eigenvalue(矩陣)
eigenvalue([2112])=1,3
eigenvector 特徵向量 計算矩陣的特徵向量,僅支援4×4或以下的矩陣
參數:eigenvector(矩陣)
eigenvector([2112])=[−1111]
row 初始化矩陣的row
參數:row(a, b, c,...row的元素)
matrix 以若干row物件初始化矩陣
參數:matrix(row_a, row_b, row_c,...矩陣的row)
isMatrix 檢查一個物件是否為矩陣
參數:isMatrix(物件)
isMatrix(1)=false
vector 初始化向量
參數:vector(a, b, c,...向量的元素)
vector(1,2,3)=[123]
rowvector 初始化row向量
參數:rowvector(a, b, c,...向量的元素)
rowvector(1,2,3)=[123]
toMatrix 嘗試從字串讀成矩陣
參數:toMatrix(字串)