Created
November 2, 2015 09:36
-
-
Save kyoro1/0cb870173e3b0b973798 to your computer and use it in GitHub Desktop.
Pythonで逆行列を求める&検算 ref: http://qiita.com/kyoro1/items/9ff500db0d519bd2a6f5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A=\left( | |
\begin{matrix} | |
1 & 2 \\ | |
3 & 4 | |
\end{matrix} | |
\right) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> import numpy as np | |
> A = np.array([[1,2],[3,4]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> np.dot(A,inv_A) | |
array([[ 1.00000000e+00, 1.11022302e-16], | |
[ 0.00000000e+00, 1.00000000e+00]]) | |
> np.dot(inv_A,A) | |
array([[ 1.00000000e+00, 4.44089210e-16], | |
[ 0.00000000e+00, 1.00000000e+00]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> A | |
array([[1, 2], | |
[3, 4]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{\rm det}(A)={\rm det}\left( | |
\begin{matrix} | |
1 & 2 \\ | |
3 & 4 | |
\end{matrix} | |
\right) | |
=1\times 4-2\times3=-2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> np.linalg.det(A) | |
-2.0000000000000004 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A = \left( | |
\begin{matrix} | |
a & b \\ | |
c & d | |
\end{matrix}\right) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A^{-1} = \frac{1}{{\rm det}A}\left( | |
\begin{matrix} | |
d & -b \\ | |
-c & a | |
\end{matrix}\right) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A^{-1} = \frac{1}{-2}\left( | |
\begin{matrix} | |
4 & -2 \\ | |
-3 & 1 | |
\end{matrix}\right) | |
=\left( | |
\begin{matrix} | |
-2 & 1 \\ | |
1.5 & -0.5 | |
\end{matrix} | |
\right) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> inv_A = np.linalg.inv(A) | |
> inv_A | |
array([[-2. , 1. ], | |
[ 1.5, -0.5]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AA^{-1}=A^{-1}A= | |
\left( | |
\begin{matrix} | |
1 & 0 \\ | |
0 & 1 | |
\end{matrix} | |
\right) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment