LoginSignup
4
4

More than 5 years have passed since last update.

PythonでTraceを計算してみる

Posted at

やりたいこと:線型代数のTraceの命題を確かめてみること

{\rm Tr}(PAP^{-1})={\rm Tr}(A)

Traceって?(一応、復習)

$n$次正方行列$A=(a_{ij})$に対して、対角成分の和を加えたもの:

{\rm Tr}(A):=\sum_{i=1}^na_{ii} 

(サンプル)行列の定義

A=\left(
\begin{matrix}
1 & 2 \\
3 & 4 
\end{matrix}
\right),
P=\left(
\begin{matrix}
2 & 3 \\
4 & 5 
\end{matrix}
\right)

とします。実装ではこんな感じ:

> import numpy as np
> A = np.array([[1,2],[3,4]])
> P = np.array([[2,3],[4,5]])

一応、中身のck

> A 
array([[1, 2],
       [3, 4]])
> P
array([[2, 3],
       [4, 5]])

Pの行列式をck

行列式が0だと逆行列が存在しないですからね。

> np.linalg.det(P)
-2.0

→大丈夫そうですね!

Traceの計算

> np.trace(np.dot(np.dot(P,A),inv_P))
5.0
> np.trace(A)
5

まぁ、そらそうだろ、という結果ですがw

勿論、これでは数学的な証明にはなり得ませんが、Pythonの練習材料として、てことで。

4
4
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
4
4