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

1 次查看(过去 30 天)
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Call 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