0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

計算ミスが減るかもしれない行列積のやり方

Last updated at Posted at 2025-04-28

行列の積

はじめに

大学に入学すると、行列の掛け算を習います。
しかし、行列の掛け算の計算は大変なことが多く、計算ミスをよくやってしまいます。

本記事では、紙に書く量は増えるものの、より間違わず行列の積が計算できる方法を紹介します。

ここで想定している行列とは

\begin{pmatrix}
a & b \\
c & d
\end{pmatrix}

大学初年次の線形代数学で導入される行列です。

行列の掛け算のルール

  • 行列$A$と$B$の積$A B$を計算するとき、$A$の列の数と$B$の行の数が一緒じゃないとダメ

行列の計算の定義式(教科書に書いてあるもの)

行列 $A$(サイズ:$m \times n$)と行列 $B$(サイズ:$n \times p$)の積 $C = AB$ は、$m \times p$ の行列になります。
$C$ の各要素 $c_{ij}$ は、次の式で計算されます。

$$
c_{ij} = \sum_{k=1}^{n} a_{ik} b_{kj}
$$

実際にやってみましょう。

計算例

$A$ $(2×3)$と$B$ $(3×2)$の積$AB$の計算

A = \begin{pmatrix}
1 & 2 & 3 \\
4 & 5 & 6
\end{pmatrix}, \quad
B = \begin{pmatrix}
7 & 8 \\
9 & 10 \\
11 & 12
\end{pmatrix}
AB = \begin{pmatrix}
(1*7 + 2*9 + 3*11) & (1*8 + 2*10 + 3*12) \\
(4*7 + 5*9 + 6*11) & (4*8 + 5*10 + 6*12)
\end{pmatrix}

皆さんは、この計算を頭の中で正しく行うことができるでしょうか?
正直、難しいと思います。私は、試験でこの計算をミスして、成績を落としました。

提案したい手法

行列の掛け算は、頭の中ですると、とても大変です。
しかし、ちょっと見方を変えてみると、すこし楽になります。

その見方は、

行列の積を簡単な行列の積に分解する

というものです。上の例でやってみます。
Aを列ベクトルに分解してみます。

A = \left[ 
\begin{pmatrix} 1 \\ 4 \end{pmatrix},\ 
\begin{pmatrix} 2 \\ 5 \end{pmatrix},\ 
\begin{pmatrix} 3 \\ 6 \end{pmatrix}
\right]

今度は、Bを行ベクトルに分解してみます。

B = \begin{bmatrix}
\begin{pmatrix} 7 & 8 \end{pmatrix} \\
\begin{pmatrix} 9 & 10 \end{pmatrix} \\
\begin{pmatrix} 11 & 12 \end{pmatrix}
\end{bmatrix}

このとき、行列の積は以下のような方法で計算することができます。

AB = 
\begin{pmatrix}
1 \\ 4
\end{pmatrix}
\begin{pmatrix}
7 & 8
\end{pmatrix}
+
\begin{pmatrix}
2 \\ 5
\end{pmatrix}
\begin{pmatrix}
9 & 10
\end{pmatrix}
+
\begin{pmatrix}
3 \\ 6
\end{pmatrix}
\begin{pmatrix}
11 & 12
\end{pmatrix}

このように、行列の積は、$$ ((n,1) 型の行列) \times ((1,n)型の行列)$$
の積に分解することができます。
それぞれの行列の積は簡単にできると思います。

つまり、行列の積を、簡単な行列の積に分解して、最後に足すことで
計算を書き起こすことができます。

計算ミスを減らしたいときに便利です。

まとめ

  • 行列の積は分解できる
  • 難しい行列の積は、分解して、最後に足すことで比較的楽になる

参考資料

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?