Inverse of a matrix in MATLAB and Python

5 ビュー (過去 30 日間)
Cool deb
Cool deb 2022 年 11 月 4 日
移動済み: KSSV 2022 年 11 月 4 日
Python code:
A= np.array([[1,2,3],[2,3,4],[3,4,5]])
print(np.linalg.inv(A))
MATLAB code:
A = [1,2,3;2,3,4;3,4,5]
inv(A)
Python Output:
[[-4.50359963e+15 9.00719925e+15 -4.50359963e+15]
[ 9.00719925e+15 -1.80143985e+16 9.00719925e+15]
[-4.50359963e+15 9.00719925e+15 -4.50359963e+15]]
Matlab Output:
ans =
1.0e+16 *
0.3002 -0.6005 0.3002
-0.6005 1.2010 -0.6005
0.3002 -0.6005 0.3002

回答 (1 件)

KSSV
KSSV 2022 年 11 月 4 日
You are to trying to fid the inverse of a singular matrix. A singular matrix is the one which doesn't have inverse. So different programming languages, different versions of the same languages might give different answers based on the math library they use.
  1 件のコメント
KSSV
KSSV 2022 年 11 月 4 日
移動済み: KSSV 2022 年 11 月 4 日
Note that it is a singular matrix.
A = [1,2,3;2,3,4;3,4,5]
A = 3×3
1 2 3 2 3 4 3 4 5
inv(A)
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.625929e-18.
ans = 3×3
1.0e+15 * -2.2518 4.5036 -2.2518 4.5036 -9.0072 4.5036 -2.2518 4.5036 -2.2518

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

タグ

製品


リリース

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by