필터 지우기
필터 지우기

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일

추가 답변 (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