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?

More than 1 year has passed since last update.

「逆行列(英:invertible matrix)」を調べた。sympyで

Last updated at Posted at 2023-11-28

wikipedia

過去問内部検索 (逆行列)

「大学入試数学問題集成」様 サイト内

ChatGPT-3.5 先生へ

逆行列とは何ですか

 >...数学や工学のさまざまな分野で重要な役割を果たします。

WolframAlpha で

結果
1/(a d - b c)(d | -b
-c | a)

(勉強中) MATLAB 追加のオプションSymbolic Math Toolbox で

sympyで

・ver0.2 逆行列を因数分解したい。行列式を分母に表示したい。
 自作関数myInv_str()で文字列で、表示です。

# ver0.2
from sympy import *

var('a,b,c,d',real=True)
def myInv_str(A):
     return "1/(" + str(det(A)) +")*" + str(A.inv()*det(A))
A=Matrix([[a,b],[c,d]])
print("#",                  A      )
print("#",                  A.inv())
print("#",        myInv_str(A)     )
print("#",sympify(myInv_str(A))    )
# Matrix([[a, b], [c, d]])
# Matrix([[d/(a*d - b*c), -b/(a*d - b*c)], [-c/(a*d - b*c), a/(a*d - b*c)]])
# 1/(a*d - b*c)*Matrix([[d, -b], [-c, a]])
# Matrix([[d/(a*d - b*c), -b/(a*d - b*c)], [-c/(a*d - b*c), a/(a*d - b*c)]])

・ver0.1
・Matrixの後ろの.factor()は動きませんでした。ページ後半で再確認しました。

inv(method=None, iszerofunc=, try_block_diag=False)
https://docs.sympy.org/latest/modules/matrices/matrices.html#sympy.matrices.matrices.MatrixBase.inv

# ver0.1
from sympy import *

var('a,b,c,d',real=True)
A=Matrix([[a,b],[c,d]])
print("#",A)
print("#",A.inv())
# print("#",A.inv().factor())
# Matrix([[a, b], [c, d]])
# Matrix([[d/(a*d - b*c), -b/(a*d - b*c)], [-c/(a*d - b*c), a/(a*d - b*c)]])
# AttributeError: 'MutableDenseMatrix' object has no attribute 'factor'

いつもの? sympyの実行環境と 参考のおすすめです。

(テンプレート)

いつもと違うおすすめです。

・Matrixの後ろの.factor()は動きませんでした。再確認しました。

0
0
1

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?