フィルターのクリア

How can we achieve the scalar ^ Matrix functionality in python.

1 回表示 (過去 30 日間)
Arslan Saif
Arslan Saif 2023 年 1 月 7 日
移動済み: Walter Roberson 2023 年 1 月 7 日
Like I have code in matlab
dt=0.005
A=[ 0 1; -394510 -62.831];
Kb=real(exp(1)^(A*dt));
I convert it in python as
kb=np.real(np.exp(1)**(A*dt))
But output is completely diff, np.exp(1) and (A*dt) gives the same output as in matlab exp(1) and (A*dt) gives. But when it comes to taking exponent ans will be different. I also tried the eigen value way which matlab uses when it calculate the scalar ^ matrix but still different outputs.
Eigen value way in python:
eigenvalues, eigenvectors = np.linalg.eig(A)
# Raise the eigenvalues to the power of the scalar
eigenvalues_raised = np.exp(1)**eigenvalues
# Multiply the resulting matrix by the inverse of the eigenvectors
result = eigenvectors.dot(np.diag(eigenvalues_raised)).dot(np.linalg.inv(eigenvectors))

採用された回答

Walter Roberson
Walter Roberson 2023 年 1 月 7 日
移動済み: Walter Roberson 2023 年 1 月 7 日
  1 件のコメント
Arslan Saif
Arslan Saif 2023 年 1 月 7 日
移動済み: Walter Roberson 2023 年 1 月 7 日
Thank you so much, it worked

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

その他の回答 (0 件)

カテゴリ

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