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

3 views (last 30 days)
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))

Accepted Answer

Walter Roberson
Walter Roberson on 7 Jan 2023
Moved: Walter Roberson on 7 Jan 2023

More Answers (0)

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!