行列のうち、\(m\)行\(1\)列のものを「列ベクトル」という。\(\boldsymbol x\)と\(\boldsymbol a\)を列ベクトル、\(c\)を定数、\(A\)を行列とした場合、以下のベクトル微分の公式が成り立つ。
- \(\displaystyle \frac{\partial}{\partial \boldsymbol x} \left( {}^t \! \boldsymbol a \boldsymbol x \right) = \boldsymbol a\)
- \(\displaystyle \frac{\partial}{\partial \boldsymbol x} \left( c \right) = \boldsymbol 0\)
- \(\displaystyle \frac{\partial}{\partial \boldsymbol x} \left( {}^t \! \boldsymbol x A \boldsymbol x \right) = (A + {}^t \! A)\boldsymbol x\)
今回は、上記3つの公式が成り立っていることを確認してみたので、その結果を共有する。
やってみたこと
ベクトル微分の公式① の確認
①\(\displaystyle \frac{\partial}{\partial \boldsymbol x} \left( {}^t \! \boldsymbol a \boldsymbol x \right) = \boldsymbol a\) を具体的な値で確認した結果は、以下の通り。
\(\boldsymbol x = \begin{pmatrix} x_1 \\ x_2 \\ x_3 \end{pmatrix} \)、\(\boldsymbol a = \begin{pmatrix} 2 \\ 3 \\ 5 \end{pmatrix} \)の場合、
\[
\begin{multline}
\shoveleft{\displaystyle \frac{\partial}{\partial \boldsymbol x} \left( {}^t \! \boldsymbol a \boldsymbol x \right)
= \frac{\partial}{\partial \boldsymbol x} \begin{pmatrix} 2 & 3 & 5 \end{pmatrix} \begin{pmatrix} x_1 \\ x_2 \\ x_3 \end{pmatrix}
= \frac{\partial}{\partial \boldsymbol x} \left( 2x_1 + 3x_2 + 5x_3 \right) } \\
\shoveleft{= \begin{pmatrix} \displaystyle \frac{\partial}{\partial x_1} \left( 2x_1 + 3x_2 + 5x_3 \right) \\
\displaystyle \frac{\partial}{\partial x_2} \left( 2x_1 + 3x_2 + 5x_3 \right) \\
\displaystyle \frac{\partial}{\partial x_3} \left( 2x_1 + 3x_2 + 5x_3 \right) \end{pmatrix}
= \begin{pmatrix} 2 + 0 + 0 \\ 0 + 3 + 0 \\ 0 + 0 + 5 \end{pmatrix}
= \begin{pmatrix} 2 \\ 3 \\ 5 \end{pmatrix} = \boldsymbol a }
\end{multline}
\]
また、①\(\displaystyle \frac{\partial}{\partial \boldsymbol x} \left( {}^t \! \boldsymbol a \boldsymbol x \right) = \boldsymbol a\) を\(m\)行の列ベクトルで確認した結果は、以下の通り。
\(\boldsymbol x = \begin{pmatrix} x_1 \\ x_2 \\ \vdots \\ x_m \end{pmatrix} \)、\(\boldsymbol a = \begin{pmatrix} a_1 \\ a_2 \\ \vdots \\ a_m \end{pmatrix} \)の場合、
\[
\begin{multline}
\shoveleft{\displaystyle \frac{\partial}{\partial \boldsymbol x} \left( {}^t \! \boldsymbol a \boldsymbol x \right)
= \frac{\partial}{\partial \boldsymbol x} \begin{pmatrix} a_1 & a_2 & \ldots & a_m \end{pmatrix} \begin{pmatrix} x_1 \\ x_2 \\ \vdots \\ x_m \end{pmatrix}
= \frac{\partial}{\partial \boldsymbol x} \left( a_1x_1 + a_2x_2 + \ldots + a_mx_m \right) } \\
\shoveleft{= \begin{pmatrix} \displaystyle \frac{\partial}{\partial x_1} \left( a_1x_1 + a_2x_2 + \ldots + a_mx_m \right) \\
\displaystyle \frac{\partial}{\partial x_2} \left( a_1x_1 + a_2x_2 + \ldots + a_mx_m \right) \\
\vdots \\
\displaystyle \frac{\partial}{\partial x_m} \left( a_1x_1 + a_2x_2 + \ldots + a_mx_m \right) \end{pmatrix}
= \begin{pmatrix} a_1 \\ a_2 \\ \vdots \\ a_m \end{pmatrix} = \boldsymbol a }
\end{multline}
\]
ベクトル微分の公式② の確認
②\(\displaystyle \frac{\partial}{\partial \boldsymbol x} \left( c \right) = \boldsymbol 0\) を具体的な値で確認した結果は、以下の通り。
\(\boldsymbol x = \begin{pmatrix} x_1 \\ x_2 \\ x_3 \end{pmatrix} \)、\(c = 5\)の場合、
\[
\begin{multline}
\shoveleft{\displaystyle \frac{\partial}{\partial \boldsymbol x}c = \displaystyle \frac{\partial}{\partial \boldsymbol x} \left( 5 \right)
= \begin{pmatrix} \displaystyle \frac{\partial}{\partial x_1} \left( 5 \right) \\
\displaystyle \frac{\partial}{\partial x_2} \left( 5 \right) \\
\displaystyle \frac{\partial}{\partial x_3} \left( 5 \right) \end{pmatrix}
= \begin{pmatrix} \displaystyle 0 \\ 0 \\ 0 \end{pmatrix} = \boldsymbol 0 }
\end{multline}
\]
また、②\(\displaystyle \frac{\partial}{\partial \boldsymbol x} \left( c \right) = \boldsymbol 0\) を\(m\)行の列ベクトルと定数\(C\)で確認した結果は、以下の通り。
\(\boldsymbol x = \begin{pmatrix} x_1 \\ x_2 \\ \ldots \\ x_m \end{pmatrix} \)、\(c = C\)の場合、
\[
\begin{multline}
\shoveleft{\displaystyle \frac{\partial}{\partial \boldsymbol x}c = \displaystyle \frac{\partial}{\partial \boldsymbol x} \left( C \right)
= \begin{pmatrix} \displaystyle \frac{\partial}{\partial x_1} \left( C \right) \\
\displaystyle \frac{\partial}{\partial x_2} \left( C \right) \\
\vdots \\
\displaystyle \frac{\partial}{\partial x_m} \left( C \right) \end{pmatrix}
= \begin{pmatrix} \displaystyle 0 \\ 0 \\ \vdots \\ 0 \end{pmatrix} = \boldsymbol 0 }
\end{multline}
\]
ベクトル微分の公式③ の確認
③\(\displaystyle \frac{\partial}{\partial \boldsymbol x} \left( {}^t \! \boldsymbol x A \boldsymbol x \right) = (A + {}^t \! A)\boldsymbol x\) を具体的な値で確認した結果は、以下の通り。
\(\boldsymbol x = \begin{pmatrix} x_1 \\ x_2 \\ x_3 \end{pmatrix} \)、\(A = \begin{pmatrix} 1 & 2 & 3 \\ 4 & 3 & 1 \\ 3 & 1 & 2 \end{pmatrix} \)の場合、
\[
\begin{multline}
\shoveleft{ {}^t \! \boldsymbol x A \boldsymbol x
= \begin{pmatrix} x_1 & x_2 & x_3 \end{pmatrix} \begin{pmatrix} 1 & 2 & 3 \\ 4 & 3 & 1 \\ 3 & 1 & 2 \end{pmatrix} \begin{pmatrix} x_1 \\ x_2 \\ x_3 \end{pmatrix}
= \begin{pmatrix} x_1 & x_2 & x_3 \end{pmatrix} \begin{pmatrix} x_1 + 2x_2 + 3x_3 \\ 4x_1 + 3x_2 + x_3 \\ 3x_1 + x_2 + 2x_3 \end{pmatrix} } \\
\shoveleft{ = x_1(x_1 + 2x_2 + 3x_3) + x_2(4x_1 + 3x_2 + x_3) + x_3(3x_1 + x_2 + 2x_3) } \\
\shoveleft{ = {x_1}^2 + 6x_1x_2 + 6x_1x_3 + 3{x_2}^2 + 2x_2x_3 + 2{x_3}^2 } \\
\shoveleft{ \displaystyle \frac{\partial}{\partial \boldsymbol x} \left( {}^t \! \boldsymbol x A \boldsymbol x \right)
= \displaystyle \frac{\partial}{\partial \boldsymbol x}
\begin{pmatrix} x_1 & x_2 & x_3 \end{pmatrix} \begin{pmatrix} 1 & 2 & 3 \\ 4 & 3 & 1 \\ 3 & 1 & 2 \end{pmatrix} \begin{pmatrix} x_1 \\ x_2 \\ x_3 \end{pmatrix} } \\
\shoveleft{ = \displaystyle \frac{\partial}{\partial \boldsymbol x} \left( {x_1}^2 + 6x_1x_2 + 6x_1x_3 + 3{x_2}^2 + 2x_2x_3 + 2{x_3}^2 \right) } \\
\shoveleft{ = \begin{pmatrix} \displaystyle \frac{\partial}{\partial x_1} \left( {x_1}^2 + 6x_1x_2 + 6x_1x_3 + 3{x_2}^2 + 2x_2x_3 + 2{x_3}^2 \right) \\
\displaystyle \frac{\partial}{\partial x_2} \left( {x_1}^2 + 6x_1x_2 + 6x_1x_3 + 3{x_2}^2 + 2x_2x_3 + 2{x_3}^2 \right) \\
\displaystyle \frac{\partial}{\partial x_3} \left( {x_1}^2 + 6x_1x_2 + 6x_1x_3 + 3{x_2}^2 + 2x_2x_3 + 2{x_3}^2 \right) \end{pmatrix}
= \begin{pmatrix} 2x_1 + 6x_2 + 6x_3 \\ 6x_1 + 6x_2 + 2x_3 \\ 6x_1 + 2x_2 + 4x_3 \end{pmatrix} } \\
\shoveleft{A + {}^t \! A = \begin{pmatrix} 1 & 2 & 3 \\ 4 & 3 & 1 \\ 3 & 1 & 2 \end{pmatrix} + \begin{pmatrix} 1 & 4 & 3 \\ 2 & 3 & 1 \\ 3 & 1 & 2 \end{pmatrix}
= \begin{pmatrix} 1+1 & 2+4 & 3+3 \\ 4+2 & 3+3 & 1+1 \\ 3+3 & 1+1 & 2+2 \end{pmatrix}
= \begin{pmatrix} 2 & 6 & 6 \\ 6 & 6 & 2 \\ 6 & 2 & 4 \end{pmatrix} } \\
\shoveleft{(A + {}^t \! A)\boldsymbol x = \begin{pmatrix} 2 & 6 & 6 \\ 6 & 6 & 2 \\ 6 & 2 & 4 \end{pmatrix} \begin{pmatrix} x_1 \\ x_2 \\ x_3 \end{pmatrix}
= \begin{pmatrix} 2x_1 + 6x_2 + 6x_3 \\ 6x_1 + 6x_2 + 2x_3 \\ 6x_1 + 2x_2 + 4x_3 \end{pmatrix}
= \displaystyle \frac{\partial}{\partial \boldsymbol x} \left( {}^t \! \boldsymbol x A \boldsymbol x \right) }
\end{multline}
\]
また、③\(\displaystyle \frac{\partial}{\partial \boldsymbol x} \left( {}^t \! \boldsymbol x A \boldsymbol x \right) = (A + {}^t \! A)\boldsymbol x\) を、\(m\)行の列ベクトルと、\(m\)行\(m\)列の正方行列で確認した結果は、以下の通り。
\(\boldsymbol x = \begin{pmatrix} x_1 \\ x_2 \\ x_3 \\ \vdots \\ x_m \end{pmatrix} \)、\(A = \begin{pmatrix} a_{11} & a_{12} & a_{13} & \ldots & a_{1m} \\
a_{21} & a_{22} & a_{23} & \ldots & a_{2m} \\ a_{31} & a_{32} & a_{33} & \ldots & a_{3m} \\ \vdots & \vdots & \vdots & \ddots & \vdots \\
a_{m1} & a_{m2} & a_{m3} & \ldots & a_{mm} \end{pmatrix} \)の場合、
\[
\begin{multline}
\shoveleft{ {}^t \! \boldsymbol x A \boldsymbol x = \begin{pmatrix} x_1 & x_2 & x_3 & \ldots & x_m \end{pmatrix} \begin{pmatrix} a_{11} & a_{12} & a_{13} & \ldots & a_{1m} \\
a_{21} & a_{22} & a_{23} & \ldots & a_{2m} \\ a_{31} & a_{32} & a_{33} & \ldots & a_{3m} \\ \vdots & \vdots & \vdots & \ddots & \vdots \\
a_{m1} & a_{m2} & a_{m3} & \ldots & a_{mm} \end{pmatrix} \begin{pmatrix} x_1 \\ x_2 \\ x_3 \\ \vdots \\ x_m \end{pmatrix} } \\
\shoveleft{ = \begin{pmatrix} x_1 & x_2 & x_3 & \ldots & x_m \end{pmatrix} \begin{pmatrix} a_{11}x_1 + a_{12}x_2 + a_{13}x_3 + \ldots + a_{1m}x_m \\
a_{21}x_1 + a_{22}x_2 + a_{23}x_3 + \ldots + a_{2m}x_m \\ a_{31}x_1 + a_{32}x_2 + a_{33}x_3 + \ldots + a_{3m}x_m \\
\vdots \\ a_{m1}x_1 + a_{m2}x_2 + a_{m3}x_3 + \ldots + a_{mm}x_m \end{pmatrix} } \\
\shoveleft{ = \begin{pmatrix} x_1 & x_2 & x_3 & \ldots & x_m \end{pmatrix} \begin{pmatrix} \displaystyle \sum_{i=1}^{m}a_{1i}x_i \\ \displaystyle \sum_{i=1}^{m}a_{2i}x_i \\
\displaystyle \sum_{i=1}^{m}a_{3i}x_i \\ \vdots \\ \displaystyle \sum_{i=1}^{m}a_{mi}x_i \end{pmatrix} } \\
\shoveleft{ = x_1\displaystyle \sum_{i=1}^{m}a_{1i}x_i + x_2\displaystyle \sum_{i=1}^{m}a_{2i}x_i + x_3\displaystyle \sum_{i=1}^{m}a_{3i}x_i
+ \ldots + x_m\displaystyle \sum_{i=1}^{m}a_{mi}x_i
= \displaystyle \sum_{k=1}^{m}x_k \left( \displaystyle \sum_{i=1}^{m}a_{ki}x_i \right) } \\
\shoveleft{ \displaystyle \frac{\partial}{\partial \boldsymbol x} \left( {}^t \! \boldsymbol x A \boldsymbol x \right)
= \displaystyle \frac{\partial}{\partial \boldsymbol x} \begin{pmatrix} x_1 & x_2 & x_3 & \ldots & x_m \end{pmatrix}
\begin{pmatrix} a_{11} & a_{12} & a_{13} & \ldots & a_{1m} \\
a_{21} & a_{22} & a_{23} & \ldots & a_{2m} \\ a_{31} & a_{32} & a_{33} & \ldots & a_{3m} \\ \vdots & \vdots & \vdots & \ddots & \vdots \\
a_{m1} & a_{m2} & a_{m3} & \ldots & a_{mm} \end{pmatrix} \begin{pmatrix} x_1 \\ x_2 \\ x_3 \\ \vdots \\ x_m \end{pmatrix} } \\
\shoveleft{ = \displaystyle \frac{\partial}{\partial \boldsymbol x} \displaystyle \sum_{k=1}^{m}x_k \left( \displaystyle \sum_{i=1}^{m}a_{ki}x_i \right)
= \begin{pmatrix} \displaystyle \frac{\partial}{\partial x_1} \displaystyle \sum_{k=1}^{m}x_k \left( \displaystyle \sum_{i=1}^{m}a_{ki}x_i \right) \\
\displaystyle \frac{\partial}{\partial x_2} \displaystyle \sum_{k=1}^{m}x_k \left( \displaystyle \sum_{i=1}^{m}a_{ki}x_i \right) \\
\displaystyle \frac{\partial}{\partial x_3} \displaystyle \sum_{k=1}^{m}x_k \left( \displaystyle \sum_{i=1}^{m}a_{ki}x_i \right) \\
\vdots \\ \displaystyle \frac{\partial}{\partial x_m} \displaystyle \sum_{k=1}^{m}x_k \left( \displaystyle \sum_{i=1}^{m}a_{ki}x_i \right) \end{pmatrix} } \\
\shoveleft{ = \begin{pmatrix} \displaystyle \frac{\partial}{\partial x_1} \{ a_{11}{x_1}^2 + (a_{12}x_2 + a_{13}x_3 + \ldots + a_{1m}x_m)x_1
+ (a_{21}x_2 + a_{31}x_3 + \ldots + a_{m1}x_m)x_1 + \ldots \} \\
\displaystyle \frac{\partial}{\partial x_2} \{ a_{22}{x_2}^2 + (a_{21}x_1 + a_{23}x_3 + \ldots + a_{2m}x_m)x_2
+ (a_{12}x_1 + a_{32}x_3 + \ldots + a_{m2}x_m)x_2 + \ldots \} \\
\displaystyle \frac{\partial}{\partial x_3} \{ a_{33}{x_3}^2 + (a_{31}x_1 + a_{32}x_2 + \ldots + a_{3m}x_m)x_3
+ (a_{13}x_1 + a_{23}x_2 + \ldots + a_{m3}x_m)x_3 + \ldots \} \\ \vdots \\
\displaystyle \frac{\partial}{\partial x_m} \{ a_{mm}{x_m}^2 + (a_{m1}x_1 + a_{m2}x_2 + a_{m3}x_3 + \ldots)x_m
+ (a_{1m}x_1 + a_{2m}x_2 + a_{3m}x_3 + \ldots)x_m + \ldots \} \end{pmatrix} } \\
\shoveleft{ = \begin{pmatrix} 2a_{11}x_1 + (a_{12}x_2 + a_{13}x_3 + \ldots + a_{1m}x_m) + (a_{21}x_2 + a_{31}x_3 + \ldots + a_{m1}x_m) \\
2a_{22}x_2 + (a_{21}x_1 + a_{23}x_3 + \ldots + a_{2m}x_m) + (a_{12}x_1 + a_{32}x_3 + \ldots + a_{m2}x_m) \\
2a_{33}x_3 + (a_{31}x_1 + a_{32}x_2 + \ldots + a_{3m}x_m) + (a_{13}x_1 + a_{23}x_2 + \ldots + a_{m3}x_m) \\ \vdots \\
2a_{mm}x_m + (a_{m1}x_1 + a_{m2}x_2 + a_{m3}x_3 + \ldots) + (a_{1m}x_1 + a_{2m}x_2 + a_{3m}x_3 + \ldots) \end{pmatrix} } \\
\shoveleft{ = \begin{pmatrix} a_{11}x_1 + (a_{12}x_2 + a_{13}x_3 + \ldots + a_{1m}x_m) + a_{11}x_1 + (a_{21}x_2 + a_{31}x_3 + \ldots + a_{m1}x_m) \\
a_{22}x_2 + (a_{21}x_1 + a_{23}x_3 + \ldots + a_{2m}x_m) + a_{22}x_2 + (a_{12}x_1 + a_{32}x_3 + \ldots + a_{m2}x_m) \\
a_{33}x_3 + (a_{31}x_1 + a_{32}x_2 + \ldots + a_{3m}x_m) + a_{33}x_3 + (a_{13}x_1 + a_{23}x_2 + \ldots + a_{m3}x_m) \\ \vdots \\
a_{mm}x_m + (a_{m1}x_1 + a_{m2}x_2 + a_{m3}x_3 + \ldots) + a_{mm}x_m + (a_{1m}x_1 + a_{2m}x_2 + a_{3m}x_3 + \ldots) \end{pmatrix} } \\
\shoveleft{ = \begin{pmatrix} (a_{11}x_1 + a_{12}x_2 + a_{13}x_3 + \ldots + a_{1m}x_m) + (a_{11}x_1 + a_{21}x_2 + a_{31}x_3 + \ldots + a_{m1}x_m) \\
(a_{21}x_1 + a_{22}x_2 + a_{23}x_3 + \ldots + a_{2m}x_m) + (a_{12}x_1 + a_{22}x_2 + a_{32}x_3 + \ldots + a_{m2}x_m) \\
(a_{31}x_1 + a_{32}x_2 + a_{33}x_3 + \ldots + a_{3m}x_m) + (a_{13}x_1 + a_{23}x_2 + a_{33}x_3 + \ldots + a_{m3}x_m) \\ \vdots \\
(a_{m1}x_1 + a_{m2}x_2 + a_{m3}x_3 + \ldots + a_{mm}x_m) + (a_{1m}x_1 + a_{2m}x_2 + a_{3m}x_3 + \ldots + a_{mm}x_m) \end{pmatrix} } \\
\shoveleft{ = \begin{pmatrix} a_{11}x_1 + a_{12}x_2 + a_{13}x_3 + \ldots + a_{1m}x_m \\
a_{21}x_1 + a_{22}x_2 + a_{23}x_3 + \ldots + a_{2m}x_m \\
a_{31}x_1 + a_{32}x_2 + a_{33}x_3 + \ldots + a_{3m}x_m \\ \vdots \\
a_{m1}x_1 + a_{m2}x_2 + a_{m3}x_3 + \ldots + a_{mm}x_m \end{pmatrix} + \begin{pmatrix} a_{11}x_1 + a_{21}x_2 + a_{31}x_3 + \ldots + a_{m1}x_m \\
a_{12}x_1 + a_{22}x_2 + a_{32}x_3 + \ldots + a_{m2}x_m \\
a_{13}x_1 + a_{23}x_2 + a_{33}x_3 + \ldots + a_{m3}x_m \\ \vdots \\
a_{1m}x_1 + a_{2m}x_2 + a_{3m}x_3 + \ldots + a_{mm}x_m \end{pmatrix} } \\
\shoveleft{ = \begin{pmatrix} a_{11} & a_{12} & a_{13} & \ldots & a_{1m} \\
a_{21} & a_{22} & a_{23} & \ldots & a_{2m} \\
a_{31} & a_{32} & a_{33} & \ldots & a_{3m} \\
\vdots & \vdots & \vdots & \ddots & \vdots \\
a_{m1} & a_{m2} & a_{m3} & \ldots & a_{mm} \end{pmatrix}
\begin{pmatrix} x_1 \\ x_2 \\ x_3 \\ \vdots \\ x_m \end{pmatrix} + \begin{pmatrix} a_{11} & a_{21} & a_{31} & \ldots & a_{m1} \\
a_{12} & a_{22} & a_{32} & \ldots & a_{m2} \\
a_{13} & a_{23} & a_{33} & \ldots & a_{m3} \\
\vdots & \vdots & \vdots & \ddots & \vdots \\
a_{1m} & a_{2m} & a_{3m} & \ldots & a_{mm} \end{pmatrix}
\begin{pmatrix} x_1 \\ x_2 \\ x_3 \\ \vdots \\ x_m \end{pmatrix} } \\
\shoveleft{ = A \boldsymbol x + {}^t \! A \boldsymbol x = (A + {}^t \! A) \boldsymbol x }
\end{multline}
\]
要点まとめ
行列のうち、\(m\)行\(1\)列のものを「列ベクトル」といい、\(\boldsymbol x\)と\(\boldsymbol a\)を列ベクトル、\(c\)を定数、\(A\)を行列とした場合、以下のベクトル微分の公式が成り立つ。
- \(\displaystyle \frac{\partial}{\partial \boldsymbol x} \left( {}^t \! \boldsymbol a \boldsymbol x \right) = \boldsymbol a\)
- \(\displaystyle \frac{\partial}{\partial \boldsymbol x} \left( c \right) = \boldsymbol 0\)
- \(\displaystyle \frac{\partial}{\partial \boldsymbol x} \left( {}^t \! \boldsymbol x A \boldsymbol x \right) = (A + {}^t \! A)\boldsymbol x\)