- KVKV-X
行列演算FUNライブラリ
行列演算FUNとは
行列演算FUNは座標変換やロボット制御、画像処理、最小二乗法などの計算に使用します。
このページではKV-X/KVで利用できる行列演算FUNライブラリを公開しています。
関連ページ
一覧
加算 (matADD)
用途例 : 複数センサの補正値合成、座標オフセット加算

KV-X
- mat1
- 行列 [0..9,0..9]
- mat2
- 行列 [0..9,0..9]
- ColNum
- 列数
- RowNum
- 行数
- result
- 行列 [0..9,0..9]
【例】
- mat1
- \begin{bmatrix} 1,&2,&3 \\ 2,&3,&4 \\ 3,&4,&5 \\ \end{bmatrix}
- mat2
- \begin{bmatrix} 3,&2,&1 \\ 4,&3,&2 \\ 5,&4,&3 \\ \end{bmatrix}
- ColNum
- 3
- RowNum
- 3
- result
- \begin{bmatrix} 4,&4,&4 \\ 6,&6,&6 \\ 8,&8,&8 \\ \end{bmatrix}
計算式
\[ \begin{bmatrix} a_{11} & a_{12} & \ldots & a_{1n} \\ a_{21} & a_{22} & \ldots & a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{n1} & a_{n2} & \ldots & a_{nn} \end{bmatrix} + \begin{bmatrix} b_{11} & b_{12} & \ldots & b_{1n} \\ b_{21} & b_{22} & \ldots & b_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ b_{n1} & b_{n2} & \ldots & b_{nn} \end{bmatrix} = \begin{bmatrix} a_{11}+b_{11} & a_{12}+b_{12} & \ldots & a_{1n}+b_{1n} \\ a_{21}+b_{21} & a_{22}+b_{22} & \ldots & a_{2n}+b_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{n1}+b_{n1} & a_{n2}+b_{n2} & \ldots & a_{nn}+b_{nn} \end{bmatrix} \]
減算 (matSUB)
用途例 : 現在位置と目標位置との差分計算、誤差ベクトル計算

KV-X
- mat1
- 行列 [0..9,0..9]
- mat2
- 行列 [0..9,0..9]
- ColNum
- 列数
- RowNum
- 行数
- result
- 行列 [0..9,0..9]
【例】
- a
- \begin{bmatrix} 1,&2,&3 \\ 2,&3,&4 \\ 3,&4,&5 \\ \end{bmatrix}
- b
- \begin{bmatrix} 3,&2,&1 \\ 4,&3,&2 \\ 5,&4,&3 \\ \end{bmatrix}
- ColNum
- 3
- RowNum
- 3
- result
- \begin{bmatrix} -2,&0,&2 \\ -2,&0,&2 \\ -2,&0,&2 \\ \end{bmatrix}
計算式
\[ \begin{bmatrix} a_{11} & a_{12} & \ldots & a_{1n} \\ a_{21} & a_{22} & \ldots & a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{n1} & a_{n2} & \ldots & a_{nn} \end{bmatrix} - \begin{bmatrix} b_{11} & b_{12} & \ldots & b_{1n} \\ b_{21} & b_{22} & \ldots & b_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ b_{n1} & b_{n2} & \ldots & b_{nn} \end{bmatrix} = \begin{bmatrix} a_{11}-b_{11} & a_{12}-b_{12} & \ldots & a_{1n}-b_{1n} \\ a_{21}-b_{21} & a_{22}-b_{22} & \ldots & a_{2n}-b_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{n1}-b_{n1} & a_{n2}-b_{n2} & \ldots & a_{nn}-b_{nn} \end{bmatrix} \]
定数倍 (matMUL)
用途例 : ゲイン調整、単位変換、スケーリング

KV-X
- mat
- 行列 [0..9,0..9]
- kk
- 倍率
- ColNum
- 列数
- RowNum
- 行数
- result
- 行列 [0..9,0..9]
【例】
- mat
- \begin{bmatrix} 1,&2,&3 \\ 2,&3,&4 \\ 3,&4,&5 \\ \end{bmatrix}
- kk
- 2.0
- ColNum
- 3
- RowNum
- 3
- result
- \begin{bmatrix} 2,&4,&6 \\ 4,&6,&8 \\ 6,&8,&10 \\ \end{bmatrix}
計算式
\[ k \begin{bmatrix} a_{11} & a_{12} & \ldots & a_{1n} \\ a_{21} & a_{22} & \ldots & a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{n1} & a_{n2} & \ldots & a_{nn} \end{bmatrix} = \begin{bmatrix} ka_{11} & ka_{12} & \ldots & ka_{1n} \\ ka_{21} & ka_{22} & \ldots & ka_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ ka_{n1} & ka_{n2} & \ldots & ka_{nn} \end{bmatrix} \]
アダマール積 (matMultiply)
用途例 : 各要素ごとの乗算を行います。画像フィルタ、重み付け計算、特徴量処理

KV-X
- mat1
- 行列 [0..9,0..9]
- mat2
- 行列 [0..9,0..9]
- ColNum
- 列数
- RowNum
- 行数
- result
- 行列 [0..9,0..9]
【例】
- mat1
- \begin{bmatrix} 1,&2,&3 \\ 2,&3,&4 \\ 3,&4,&5 \\ \end{bmatrix}
- mat2
- \begin{bmatrix} 3,&2,&1 \\ 4,&3,&2 \\ 5,&4,&3 \\ \end{bmatrix}
- ColNum
- 3
- RowNum
- 3
- result
- \begin{bmatrix} 3,&4,&3 \\ 8,&9,&8 \\ 15,&16,&15 \\ \end{bmatrix}
\[ \begin{bmatrix} a_{11} & a_{12} & \ldots & a_{1n} \\ a_{21} & a_{22} & \ldots & a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{n1} & a_{n2} & \ldots & a_{nn} \end{bmatrix} \circ \begin{bmatrix} b_{11} & b_{12} & \ldots & b_{1n} \\ b_{21} & b_{22} & \ldots & b_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ b_{n1} & b_{n2} & \ldots & b_{nn} \end{bmatrix} = \begin{bmatrix} a_{11}b_{11} & a_{12}b_{12} & \ldots & a_{1n}b_{1n} \\ a_{21}b_{21} & a_{22}b_{22} & \ldots & a_{2n}b_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{n1}b_{n1} & a_{n2}b_{n2} & \ldots & a_{nn}b_{nn} \end{bmatrix} \]
内積 (matDot)
用途例 : ベクトル類似度、フロベニウス内積、類似度評価

KV-X
- mat1
- 行列 [0..9,0..9]
- mat2
- 行列 [0..9,0..9]
- ColNum
- 列数
- RowNum
- 行数
- result
- 結果
【例】
- mat1
- \begin{bmatrix} 1,&2,&3 \\ 2,&3,&4 \\ 3,&4,&5 \\ \end{bmatrix}
- mat2
- \begin{bmatrix} 3,&2,&1 \\ 4,&3,&2 \\ 5,&4,&3 \\ \end{bmatrix}
- result
- 81
行列積 (matCross)
用途例 : 座標変換、回転変換、ロボットアーム運動学、状態空間制御
※本ライブラリでは matCross を行列積として実装しています。

KV-X
- mat1
- 行列 [0..9,0..9]
- Mat1_ColNum
- mat1列数
- Mat1_RowNum
- mat1行数
- mat2
- 行列 [0..9,0..9]
- Mat2_ColNum
- mat2列数
- Mat2_RowNum
- mat2行数
- result
- 結果 [0..9,0..9]
【例】
- mat1
- \begin{bmatrix} 1,&2,&3 \\ 2,&3,&4 \\ 3,&4,&5 \\ \end{bmatrix}
- mat2
- \begin{bmatrix} 3,&2,&1 \\ 4,&3,&2 \\ 5,&4,&3 \\ \end{bmatrix}
- Mat1_ColNum
- 3
- Mat1_RowNum
- 3
- Mat2_ColNum
- 3
- Mat2_RowNum
- 3
- result
- \begin{bmatrix} 26,&20,&14 \\ 38,&29,&20 \\ 50,&38,&26 \\ \end{bmatrix}
計算式
\[ C=A \times B \] \[ c_{ij} = \sum_{k=1}^{n} a_{ik}b_{kj} \] \[ \begin{bmatrix} c_{11} & c_{12} \\ c_{21} & c_{22} \end{bmatrix} = \begin{bmatrix} a_{11} & a_{12} \\ a_{21} & a_{22} \end{bmatrix} \begin{bmatrix} b_{11} & b_{12} \\ b_{21} & b_{22} \end{bmatrix} = \begin{bmatrix} a_{11}b_{11}+a_{12}b_{21} & a_{11}b_{12}+a_{12}b_{22} \\ a_{21}b_{11}+a_{22}b_{21} & a_{21}b_{12}+a_{22}b_{22} \end{bmatrix} \]
転置行列 (matT)
用途例 : 最小二乗法、共分散行列計算

KV-X
- mat
- 行列 [0..9,0..9]
- ColNum
- 列数
- RowNum
- 行数
- result
- 結果 [0..9,0..9]
【例】
- mat
- \begin{bmatrix} 1,&2,&3 \\ 4,&5,&6 \\ 7,&8,&9 \\ \end{bmatrix}
- ColNum
- 3
- RowNum
- 3
- result
- \begin{bmatrix} 1,&4,&7 \\ 2,&5,&8 \\ 3,&6,&9 \\ \end{bmatrix}
計算式
\[ A= \begin{bmatrix} a_{11} & a_{12} & \ldots & a_{1n} \\ a_{21} & a_{22} & \ldots & a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{n1} & a_{n2} & \ldots & a_{nn} \end{bmatrix} \] \[ A^t= \begin{bmatrix} a_{11} & a_{21} & \ldots & a_{n1} \\ a_{12} & a_{22} & \ldots & a_{n2} \\ \vdots & \vdots & \ddots & \vdots \\ a_{1n} & a_{2n} & \ldots & a_{nn} \end{bmatrix} \]
逆行列 (matInv)
用途例 : 連立方程式の解法、座標変換の逆変換、制御演算

KV-X
- mat
- 行列 [0..9,0..9]
- RowColNum
- 行数と列数
- result
- 結果 [0..9,0..9]
【例】
- mat
- \begin{bmatrix} 1,&2,&0 \\ -1,&1,&2 \\ 2,&0,&1 \\ \end{bmatrix}
- RowColNum
- 3
- result
- \begin{bmatrix} 0.09,&-0.18,&0.36 \\ 0.45,&0.09,&-0.18 \\ -0.18,&0.36,&0.27 \\ \end{bmatrix}
計算式
\[ AA^{-1}=A^{-1}A=I \] \[ I= \begin{bmatrix} 1 & 0 & \cdots & 0\\ 0 & 1 & \cdots & 0\\ \vdots & \vdots & \ddots & \vdots\\ 0 & 0 & \cdots & 1 \end{bmatrix} \]
計算例
\[ A= \begin{bmatrix} a & b\\ c & d \end{bmatrix} \] \[ A^{-1} = \frac{1}{ad-bc} \begin{bmatrix} d & -b\\ -c & a \end{bmatrix} \]
行列式の計算 (matDet)
用途例 : 逆行列が存在するか判定、特異行列の判定

KV-X
- mat
- 行列 [0..9,0..9]
- RowColNum
- 行数と列数
- result
- 計算結果
【例】
- mat
- \begin{bmatrix} 2,&-2,&4 \\ 2,&-1,&6 \\ 3,&-2,&12 \\ \end{bmatrix}
- RowColNum
- 3
- out
- 8.0
計算例
\[ A= \begin{bmatrix} a_{11} & a_{12} & a_{13}\\ a_{21} & a_{22} & a_{23}\\ a_{31} & a_{32} & a_{33} \end{bmatrix} \] \[ \det(A) = a_{11}(a_{22}a_{33}-a_{23}a_{32}) -a_{12}(a_{21}a_{33}-a_{23}a_{31}) +a_{13}(a_{21}a_{32}-a_{22}a_{31}) \]
